use of teetime.framework.Execution in project TeeTime by teetime-framework.
the class CipherTest method executeTestWithConfigurationCreatedByBuilder.
@Test
public void executeTestWithConfigurationCreatedByBuilder() throws IOException {
final Configuration configuration = ConfigurationBuilder.from(new InitialElementProducer<File>(new File(INPUT_FILE))).to(new File2ByteArray()).to(new CipherStage(PASSWORD, CipherMode.ENCRYPT)).to(new ZipByteArray(ZipMode.COMP)).to(new ZipByteArray(ZipMode.DECOMP)).to(new CipherStage(PASSWORD, CipherMode.DECRYPT)).end(new ByteArrayFileWriter(new File(OUTPUT_FILE)));
final Execution<Configuration> execution = new Execution<Configuration>(configuration);
execution.executeBlocking();
Assert.assertTrue(Files.equal(new File(INPUT_FILE), new File(OUTPUT_FILE)));
}
use of teetime.framework.Execution in project TeeTime by teetime-framework.
the class WordCounterTest method main.
public static void main(final String[] args) throws UnsupportedEncodingException, FileNotFoundException {
// http://www.loremipsum.de/downloads/original.txt
String numWorkerThreadsParam = (args.length > 0) ? args[0] : "3";
String numWarmUpsParam = (args.length > 1) ? args[1] : "1";
String fileNameParam = (args.length > 2) ? args[2] : "no default file name";
String monitoringEnabledParam = (args.length > 3) ? args[3] : "true";
int numWorkerThreads = parseAsInteger(numWorkerThreadsParam, 3);
LOGGER.info("# worker threads: " + numWorkerThreads);
int numWarmUps = parseAsInteger(numWarmUpsParam, 1);
LOGGER.info("# warm ups: " + numWarmUps);
final String fileName = fileNameParam;
final File testFile = new File(fileName);
LOGGER.info("Reading {}", testFile.getAbsolutePath());
boolean monitoringEnabled = Boolean.valueOf(monitoringEnabledParam);
final long[] timings = new long[1];
final StopWatch stopWatch = new StopWatch();
for (int i = 0; i < numWarmUps; i++) {
LOGGER.info("Warm up #" + i);
final WordCounterConfiguration wcc = new WordCounterConfiguration(numWorkerThreads, testFile);
final Execution<?> analysis = new Execution<WordCounterConfiguration>(wcc);
stopWatch.start();
analysis.executeBlocking();
stopWatch.end();
LOGGER.info("duration: " + TimeUnit.NANOSECONDS.toSeconds(stopWatch.getDurationInNs()) + " secs");
}
LOGGER.info("Starting analysis...");
final WordCounterConfiguration wcc = new WordCounterConfiguration(numWorkerThreads, testFile);
final Execution<?> analysis = new Execution<WordCounterConfiguration>(wcc);
if (monitoringEnabled) {
wcc.getMonitoringThread().start();
}
stopWatch.start();
analysis.executeBlocking();
stopWatch.end();
wcc.getMonitoringThread().terminate();
LOGGER.info("duration: " + TimeUnit.NANOSECONDS.toSeconds(stopWatch.getDurationInNs()) + " secs");
timings[0] = stopWatch.getDurationInNs();
// results for some words to verify the correctness of the word counter
final CountingMap<String> map = wcc.getResult();
System.out.println("vero: " + (map.get("vero") == 3813850) + "->" + map.get("vero") + " should be " + 3813850);
System.out.println("sit: " + (map.get("sit") == 7627700) + "->" + map.get("sit") + " should be " + 7627700);
final File outputFile = new File("timings.txt");
writeTimingsToFile(outputFile, timings);
// some statistics about the output pipes of the distributor
System.out.println("distributor pipes:");
for (final AbstractPort<?> port : wcc.getDistributorPorts()) {
final IMonitorablePipe spscPipe = (IMonitorablePipe) port.getPipe();
System.out.println("numWaits: " + spscPipe.getNumWaits());
}
System.out.println("distributor waits: " + ((NonBlockingRoundRobinStrategy) wcc.getDistributor().getStrategy()).getNumWaits());
// some statistics about the output pipes of the distributor
System.out.println("merger pipes:");
for (final AbstractPort<?> port : wcc.getMergerPorts()) {
final IMonitorablePipe spscPipe = (IMonitorablePipe) port.getPipe();
System.out.println("numWaits: " + spscPipe.getNumWaits());
}
}
use of teetime.framework.Execution in project TeeTime by teetime-framework.
the class MultipleExecutionsProducerIT method testRegularExecution.
void testRegularExecution(final List<String> expectedElements, final int numThreads) {
for (int numOfExecutions = 1; numOfExecutions < expectedElements.size() + 1; numOfExecutions++) {
List<String> actualElements = new ArrayList<>();
Configuration configuration = new Configuration().from(new ResponsiveProducer<String>(expectedElements)).end(new CollectorSink<String>(actualElements));
GlobalTaskPoolScheduling scheduler = new GlobalTaskPoolScheduling(numThreads, configuration, numOfExecutions);
Execution<Configuration> execution = new Execution<>(configuration, true, scheduler);
execution.executeBlocking();
assertThat("failed with numOfExecutions=" + numOfExecutions, actualElements, is(equalTo(expectedElements)));
}
}
use of teetime.framework.Execution in project TeeTime by teetime-framework.
the class ParallelCounterConfigIT method testParallelExecution.
private void testParallelExecution(final int numElements, final int numThreads, final int numExecutions) {
List<Integer> processedElements = new ArrayList<>();
ParallelCounterConfig config = new ParallelCounterConfig(numElements, numThreads, processedElements);
TeeTimeScheduler scheduling = new GlobalTaskPoolScheduling(numThreads, config, numExecutions);
Execution<ParallelCounterConfig> execution = new Execution<>(config, true, scheduling);
execution.executeBlocking();
for (int i = 0; i < numElements; i++) {
assertThat(processedElements.get(i), is(i));
}
assertThat(processedElements, hasSize(numElements));
}
use of teetime.framework.Execution in project TeeTime by teetime-framework.
the class PipelineIT method shouldExecutePipelineCorrectlyThreeElementsWith3ExecutionsPerTask.
@Test
public void shouldExecutePipelineCorrectlyThreeElementsWith3ExecutionsPerTask() {
String[] inputElements = { "a", "b", "c" };
GlobalTaskPoolConfig<String> config = new GlobalTaskPoolConfig<>(inputElements);
TeeTimeScheduler scheduling = new GlobalTaskPoolScheduling(NUM_THREADS, config, 3);
Execution<GlobalTaskPoolConfig<String>> execution = new Execution<>(config, true, scheduling);
execution.executeBlocking();
List<String> processedElements = config.getSink().getElements();
List<String> expectedElements = Arrays.asList("a", "b", "c");
assertThat(WRONG_PIPELINE_EXECUTION, processedElements, is(equalTo(expectedElements)));
}
Aggregations