Search in sources :

Example 76 with CompletionException

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()));
    }
}
Also used : AssertionSinks(com.hazelcast.jet.pipeline.test.AssertionSinks) Arrays(java.util.Arrays) JetInstance(com.hazelcast.jet.JetInstance) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) Processors(com.hazelcast.jet.core.processor.Processors) ParallelStreamP(com.hazelcast.jet.pipeline.test.ParallelStreamP) HazelcastSerialParametersRunnerFactory(com.hazelcast.test.HazelcastSerialParametersRunnerFactory) JetAssert.assertFalse(com.hazelcast.jet.core.test.JetAssert.assertFalse) JetAssert.assertTrue(com.hazelcast.jet.core.test.JetAssert.assertTrue) Nonnull(javax.annotation.Nonnull) Job(com.hazelcast.jet.Job) Before(org.junit.Before) UseParametersRunnerFactory(org.junit.runners.Parameterized.UseParametersRunnerFactory) PredicateEx(com.hazelcast.function.PredicateEx) FunctionEx(com.hazelcast.function.FunctionEx) AfterClass(org.junit.AfterClass) LongStream(java.util.stream.LongStream) HazelcastParametrizedRunner(com.hazelcast.test.HazelcastParametrizedRunner) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) Parameter(org.junit.runners.Parameterized.Parameter) ProcessorMetaSupplier(com.hazelcast.jet.core.ProcessorMetaSupplier) Collection(java.util.Collection) Test(org.junit.Test) CompletionException(java.util.concurrent.CompletionException) Traversers(com.hazelcast.jet.Traversers) Serializable(java.io.Serializable) Objects(java.util.Objects) JetAssert.fail(com.hazelcast.jet.core.test.JetAssert.fail) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) GeneratorFunction(com.hazelcast.jet.pipeline.test.GeneratorFunction) Hazelcast(com.hazelcast.core.Hazelcast) AssertionCompletedException(com.hazelcast.jet.pipeline.test.AssertionCompletedException) LongAccumulator(com.hazelcast.jet.accumulator.LongAccumulator) Functions.wholeItem(com.hazelcast.function.Functions.wholeItem) Assert(org.junit.Assert) AssertionCompletedException(com.hazelcast.jet.pipeline.test.AssertionCompletedException) CompletionException(java.util.concurrent.CompletionException) Job(com.hazelcast.jet.Job) Test(org.junit.Test)

Example 77 with CompletionException

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;
}
Also used : ResolutionException(com.github.anba.es6draft.runtime.modules.ResolutionException) ScriptException(com.github.anba.es6draft.runtime.internal.ScriptException) InternalThrowable(com.github.anba.es6draft.runtime.internal.InternalThrowable) CompletionException(java.util.concurrent.CompletionException) NoSuchFileException(java.nio.file.NoSuchFileException) IOException(java.io.IOException)

Example 78 with CompletionException

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());
}
Also used : BeforeClass(org.junit.BeforeClass) ByteArrayInputStream(java.io.ByteArrayInputStream) After(org.junit.After) Assert.fail(org.junit.Assert.fail) Path(java.nio.file.Path) PythonTransforms.mapUsingPythonBatch(com.hazelcast.jet.python.PythonTransforms.mapUsingPythonBatch) Before(org.junit.Before) SimpleTestInClusterSupport(com.hazelcast.jet.SimpleTestInClusterSupport) Config(com.hazelcast.config.Config) IOUtil(com.hazelcast.internal.nio.IOUtil) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Files(java.nio.file.Files) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Sinks(com.hazelcast.jet.pipeline.Sinks) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) Category(org.junit.experimental.categories.Category) File(java.io.File) TestSources(com.hazelcast.jet.pipeline.test.TestSources) Paths(java.nio.file.Paths) Assert.assertFalse(org.junit.Assert.assertFalse) InputStream(java.io.InputStream) CompletionException(java.util.concurrent.CompletionException) File(java.io.File) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) Pipeline(com.hazelcast.jet.pipeline.Pipeline) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 79 with CompletionException

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
    }
}
Also used : CompletionException(java.util.concurrent.CompletionException) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Category(org.junit.experimental.categories.Category) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 80 with CompletionException

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
    }
}
Also used : CompletionException(java.util.concurrent.CompletionException) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Category(org.junit.experimental.categories.Category) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

CompletionException (java.util.concurrent.CompletionException)199 Test (org.junit.Test)80 CompletableFuture (java.util.concurrent.CompletableFuture)62 List (java.util.List)52 ArrayList (java.util.ArrayList)51 IOException (java.io.IOException)45 Map (java.util.Map)39 Collection (java.util.Collection)31 ExecutionException (java.util.concurrent.ExecutionException)31 HashMap (java.util.HashMap)30 Collections (java.util.Collections)24 TimeUnit (java.util.concurrent.TimeUnit)22 Collectors (java.util.stream.Collectors)22 FlinkException (org.apache.flink.util.FlinkException)22 Before (org.junit.Before)21 Duration (java.time.Duration)19 Arrays (java.util.Arrays)19 BeforeClass (org.junit.BeforeClass)19 ExecutorService (java.util.concurrent.ExecutorService)18 Nonnull (javax.annotation.Nonnull)17