Search in sources :

Example 1 with OperatorTranslator

use of org.apache.beam.sdk.extensions.euphoria.core.translate.OperatorTranslator in project beam by apache.

the class GenericTranslatorProviderTest method testPredicateToTranslatorFunction.

@Test
public void testPredicateToTranslatorFunction() {
    AtomicBoolean predicateEvalValue = new AtomicBoolean(false);
    String translatorName = "translator";
    GenericTranslatorProvider provider = GenericTranslatorProvider.newBuilder().register(op -> predicateEvalValue.get(), AnyOpTranslator.ofName(translatorName)).build();
    Optional<OperatorTranslator<Void, Void, TestOperator>> maybeTranslator;
    maybeTranslator = provider.findTranslator(TestOperator.of());
    Assert.assertFalse(maybeTranslator.isPresent());
    Optional<OperatorTranslator<Void, Void, SecondTestOperator>> maybeSecondTranslator = provider.findTranslator(SecondTestOperator.of());
    Assert.assertFalse(maybeSecondTranslator.isPresent());
    predicateEvalValue.set(true);
    // now predicate will return true and we should get our translator
    maybeTranslator = provider.findTranslator(TestOperator.of());
    ProviderTestUtils.assertTranslator(translatorName, maybeTranslator, AnyOpTranslator.class);
    // we should get our translator for every operator's type
    maybeSecondTranslator = provider.findTranslator(SecondTestOperator.of());
    Assert.assertTrue(maybeSecondTranslator.isPresent());
}
Also used : OperatorTranslator(org.apache.beam.sdk.extensions.euphoria.core.translate.OperatorTranslator) TestOpTranslator(org.apache.beam.sdk.extensions.euphoria.core.translate.provider.ProviderTestUtils.TestOpTranslator) Optional(java.util.Optional) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AnyOpTranslator(org.apache.beam.sdk.extensions.euphoria.core.translate.provider.ProviderTestUtils.AnyOpTranslator) Test(org.junit.Test) SecondTestOperator(org.apache.beam.sdk.extensions.euphoria.core.translate.provider.ProviderTestUtils.SecondTestOperator) TestOperator(org.apache.beam.sdk.extensions.euphoria.core.translate.provider.ProviderTestUtils.TestOperator) Assert(org.junit.Assert) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OperatorTranslator(org.apache.beam.sdk.extensions.euphoria.core.translate.OperatorTranslator) Test(org.junit.Test)

Example 2 with OperatorTranslator

use of org.apache.beam.sdk.extensions.euphoria.core.translate.OperatorTranslator in project beam by apache.

the class GenericTranslatorProviderTest method testClassWithPredicateToTranslatorFunction.

@Test
public void testClassWithPredicateToTranslatorFunction() {
    AtomicBoolean predicateEvalValue = new AtomicBoolean(false);
    String translatorName = "translator";
    GenericTranslatorProvider provider = GenericTranslatorProvider.newBuilder().register(TestOperator.class, op -> predicateEvalValue.get(), TestOpTranslator.ofName(translatorName)).build();
    Optional<OperatorTranslator<Void, Void, TestOperator>> maybeTranslator;
    maybeTranslator = provider.findTranslator(TestOperator.of());
    Assert.assertFalse(maybeTranslator.isPresent());
    predicateEvalValue.set(true);
    // now predicate will return true and we should get our translator
    maybeTranslator = provider.findTranslator(TestOperator.of());
    ProviderTestUtils.assertTranslator(translatorName, maybeTranslator, TestOpTranslator.class);
    // we should not obtain operator for different operator class
    Optional<OperatorTranslator<Void, Void, SecondTestOperator>> maybeSecondTranslator = provider.findTranslator(SecondTestOperator.of());
    Assert.assertFalse(maybeSecondTranslator.isPresent());
}
Also used : OperatorTranslator(org.apache.beam.sdk.extensions.euphoria.core.translate.OperatorTranslator) TestOpTranslator(org.apache.beam.sdk.extensions.euphoria.core.translate.provider.ProviderTestUtils.TestOpTranslator) Optional(java.util.Optional) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AnyOpTranslator(org.apache.beam.sdk.extensions.euphoria.core.translate.provider.ProviderTestUtils.AnyOpTranslator) Test(org.junit.Test) SecondTestOperator(org.apache.beam.sdk.extensions.euphoria.core.translate.provider.ProviderTestUtils.SecondTestOperator) TestOperator(org.apache.beam.sdk.extensions.euphoria.core.translate.provider.ProviderTestUtils.TestOperator) Assert(org.junit.Assert) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OperatorTranslator(org.apache.beam.sdk.extensions.euphoria.core.translate.OperatorTranslator) SecondTestOperator(org.apache.beam.sdk.extensions.euphoria.core.translate.provider.ProviderTestUtils.SecondTestOperator) TestOperator(org.apache.beam.sdk.extensions.euphoria.core.translate.provider.ProviderTestUtils.TestOperator) Test(org.junit.Test)

Aggregations

Optional (java.util.Optional)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 OperatorTranslator (org.apache.beam.sdk.extensions.euphoria.core.translate.OperatorTranslator)2 AnyOpTranslator (org.apache.beam.sdk.extensions.euphoria.core.translate.provider.ProviderTestUtils.AnyOpTranslator)2 SecondTestOperator (org.apache.beam.sdk.extensions.euphoria.core.translate.provider.ProviderTestUtils.SecondTestOperator)2 TestOpTranslator (org.apache.beam.sdk.extensions.euphoria.core.translate.provider.ProviderTestUtils.TestOpTranslator)2 TestOperator (org.apache.beam.sdk.extensions.euphoria.core.translate.provider.ProviderTestUtils.TestOperator)2 Assert (org.junit.Assert)2 Test (org.junit.Test)2