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());
}
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());
}
Aggregations