use of java.util.concurrent.CompletionException in project hazelcast by hazelcast.
the class OrderedStreamProcessingTest method when_source_is_parallel.
@Test
public void when_source_is_parallel() {
int validatedItemCountPerGenerator = ITEM_COUNT;
int eventsPerSecondPerGenerator = 5 * ITEM_COUNT;
int generatorCount = 4;
// Generate monotonic increasing items that are distinct for each generator.
GeneratorFunction<Long> generator1 = (ts, seq) -> generatorCount * seq;
GeneratorFunction<Long> generator2 = (ts, seq) -> generatorCount * seq + 1;
GeneratorFunction<Long> generator3 = (ts, seq) -> generatorCount * seq + 2;
GeneratorFunction<Long> generator4 = (ts, seq) -> generatorCount * seq + 3;
StreamStage<Long> srcStage = p.readFrom(itemsParallel(eventsPerSecondPerGenerator, Arrays.asList(generator1, generator2, generator3, generator4))).withIngestionTimestamps();
StreamStage<Long> applied = srcStage.apply(transform);
applied.mapStateful(() -> create(generatorCount), this::orderValidator).writeTo(AssertionSinks.assertCollectedEventually(60, list -> {
assertTrue("when", validatedItemCountPerGenerator <= list.size());
assertFalse("There is some reordered items in the list", list.contains(false));
}));
Job job = jet.newJob(p);
try {
job.join();
fail("Job should have completed with an AssertionCompletedException, but completed normally");
} catch (CompletionException e) {
String errorMsg = e.getCause().getMessage();
assertTrue("Job was expected to complete with AssertionCompletedException, but completed with: " + e.getCause(), errorMsg.contains(AssertionCompletedException.class.getName()));
}
}
use of java.util.concurrent.CompletionException in project es6draft by anba.
the class ModuleOperations method toScriptException.
private static ScriptException toScriptException(ExecutionContext cx, Throwable e, SourceIdentifier moduleId, SourceIdentifier referredId) {
if (e instanceof CompletionException && e.getCause() != null) {
e = e.getCause();
}
ScriptException exception;
if (e instanceof NoSuchFileException) {
exception = new ResolutionException(Messages.Key.ModulesUnresolvedModule, moduleId.toString(), referredId.toString()).toScriptException(cx);
} else if (e instanceof IOException) {
exception = newInternalError(cx, e, Messages.Key.ModulesIOException, Objects.toString(e.getMessage(), ""));
} else if (e instanceof InternalThrowable) {
exception = ((InternalThrowable) e).toScriptException(cx);
} else {
cx.getRuntimeContext().getErrorReporter().accept(cx, e);
exception = newInternalError(cx, e, Messages.Key.InternalError, Objects.toString(e.getMessage(), ""));
}
return exception;
}
use of java.util.concurrent.CompletionException in project hazelcast by hazelcast.
the class PythonInitCleanupTest method when_jobFails_then_cleanupExecutes.
@Test
public void when_jobFails_then_cleanupExecutes() throws IOException {
// Given
String baseDirStr = baseDir.toString();
String outcomeFilename = "cleanup_outcome.txt";
installFileToBaseDir(prepareSimpleCleanupSh(baseDirStr, outcomeFilename), "cleanup.sh");
PythonServiceConfig cfg = new PythonServiceConfig().setBaseDir(baseDir.toString()).setHandlerModule("echo").setHandlerFunction("handle");
Pipeline p = Pipeline.create();
p.readFrom(TestSources.items("1")).<String>map(t -> {
throw new Exception("expected failure");
}).apply(mapUsingPythonBatch(cfg)).setLocalParallelism(2).writeTo(Sinks.logger());
// When
try {
instance().getJet().newJob(p).join();
fail();
} catch (CompletionException ex) {
// expected
}
// Then
assertTrue("Cleanup script didn't run", new File(baseDir, outcomeFilename).isFile());
}
use of java.util.concurrent.CompletionException in project hazelcast by hazelcast.
the class PythonServiceTest method batchStage_mapUsingPythonException.
@Test
@Category(NightlyTest.class)
public void batchStage_mapUsingPythonException() throws IOException {
// Given
installFileToBaseDir(FAILING_FUNCTION, "failing.py");
PythonServiceConfig cfg = new PythonServiceConfig().setBaseDir(baseDir.toString()).setHandlerModule("failing").setHandlerFunction("handle");
Pipeline p = Pipeline.create();
BatchStage<String> stage = p.readFrom(TestSources.items("1"));
// When
stage.apply(mapUsingPythonBatch(cfg)).setLocalParallelism(2).writeTo(Sinks.logger());
// Then
try {
instance().getJet().newJob(p).join();
fail();
} catch (CompletionException ex) {
// expected
}
}
use of java.util.concurrent.CompletionException in project hazelcast by hazelcast.
the class PythonServiceTest method streamStage_mapUsingPythonFailure.
@Test
@Category(NightlyTest.class)
public void streamStage_mapUsingPythonFailure() {
// Given
PythonServiceConfig cfg = new PythonServiceConfig().setBaseDir(baseDir.toString()).setHandlerModule("echo").setHandlerFunction("notExistsFunction");
Pipeline p = Pipeline.create();
StreamStage<String> stage = p.readFrom(TestSources.items("1")).addTimestamps(x -> 0, 0);
// When
stage.apply(mapUsingPython(cfg)).setLocalParallelism(2).writeTo(Sinks.logger());
// Then
try {
instance().getJet().newJob(p).join();
fail();
} catch (CompletionException ex) {
// expected
}
}
Aggregations