Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 1&1 Internet AG, https://github.com/1and1/ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package net.oneandone.jasmin.model;
 
 import org.junit.Test;
 
 
 import static org.junit.Assert.assertEquals;
 
 public class ConcurrentEngineTest {
     private static final int FACTOR = 1;
 
     private static final World WORLD = new World();
 
     private static Repository repository() throws IOException {
         Module module;
         Repository repository;
 
         repository = new Repository();
 
         module = new Module("foo"new Source(null"g""foo""1""scm"));
         module.files().add(new File(.resource("multiuser/foo.css"), null.null));
         repository.add(module);
 
         module = new Module("bar"new Source(null"g""bar""1""scm"));
         module.files().add(new File(.resource("multiuser/bar.css"), null.null));
         repository.add(module);
         return repository;
     }
 
     @Test
     public void singlethreaded() throws Throwable {
         Engine engine;
 
         engine = new Engine(repository(), 1, 1000, 1000);
         engine.request("css/foo");
     }
     @Test
     public void cachehits() throws Throwable {
         Engine engine;
 
         engine = new Engine(repository(), 15, 1000, 1000);
         parallel(engine, 2, 1000 * );
         parallel(engine, 3, 997 * );
         parallel(engine, 7, 997 * );
         parallel(engine, 13, 997 * );
     }
 
     @Test
     public void trashing() throws Throwable {
         Engine engine;
 
         engine = new Engine(repository(), 15, 0, 0);
         parallel(engine, 2, 1000 * );
         parallel(engine, 3, 997 * );
         parallel(engine, 7, 997 * );
         parallel(engine, 13, 997 * );
     }
 
     @Test
     public void trashingWithOneProcessor() throws Throwable {
         Engine engine;
 
         engine = new Engine(repository(), 1, 0, 0);
         parallel(engine, 2, 1000 * );
         parallel(engine, 3, 997 * );
         parallel(engine, 7, 997 * );
         parallel(engine, 13, 997 * );
 
         // because the hashCache always misses first:
         assertEquals(0, engine.contentCache.gets());
         assertEquals(0, engine.contentCache.misses());
     }
 
     private void parallel(Engine engineint threadCountint repeatthrows Throwable {
         ProcessThread[] threads;
         int idx;
 
         threads = new ProcessThread[threadCount];
         for (int i = 0; i < threads.lengthi++) {
             idx  = i % engine.repository.modules().size();
             threads[i] = new ProcessThread(enginerepeat"css/" + engine.repository.modules().get(idx).getName());
             threads[i].start();
         }
        for (ProcessThread thread : threads) {
            thread.finish();
        }
        assertEquals(0, engine.load());
    }
    private static class ProcessThread extends Thread {
        private final Engine engine;
        private final String path;
        private final int repeat;
        private Throwable exception;
        public ProcessThread(Engine engineint repeatString path) {
            this. = engine;
            this. = path;
            this. = repeat;
            this. = null;
        }
        @Override
        public void run() {
            String expected;
            String actual;
            expected = null;
            for (int j = 0; j < j++) {
                try {
                    actual = .request();
                    if (expected == null) {
                        expected = actual;
                    } else {
                        assertEquals(expectedactual);
                    }
                } catch (Throwable e) {
                     = e;
                    return;
                }
            }
        }
        public void finish() throws Throwable {
            join();
            if ( != null) {
                throw ;
            }
        }
    }
New to GrepCode? Check out our FAQ X