use of org.talend.sdk.component.runtime.input.InputImpl in project component-runtime by Talend.
the class ComponentExtensionTest method sourceCollectorParallel.
@Test
void sourceCollectorParallel() {
final CountDownLatch latch = new CountDownLatch(1);
final Mapper mapper = new PartitionMapperImpl() {
@Override
public long assess() {
return 2;
}
@Override
public List<Mapper> split(final long desiredSize) {
assertEquals(1, desiredSize);
return asList(this, this);
}
@Override
public Input create() {
return new InputImpl() {
private final AtomicBoolean done = new AtomicBoolean();
@Override
public Object next() {
try {
latch.await(1, MINUTES);
} catch (final InterruptedException e) {
Thread.interrupted();
fail();
}
return done.compareAndSet(false, true) ? Thread.currentThread().getName() : null;
}
@Override
protected Stream<Method> findMethods(final Class<? extends Annotation> marker) {
return Stream.empty();
}
};
}
@Override
protected Stream<Method> findMethods(final Class<? extends Annotation> marker) {
return Stream.empty();
}
};
latch.countDown();
final Stream<String> collect = handler.collect(String.class, mapper, 2, 2);
final List<String> threads = collect.collect(toList());
assertEquals(threads.toString(), 2, threads.size());
threads.forEach(n -> assertTrue(n, n.startsWith("ComponentExtension-pool-")));
}
use of org.talend.sdk.component.runtime.input.InputImpl in project component-runtime by Talend.
the class SimpleComponentRuleTest method sourceCollectorParallel.
@Test
public void sourceCollectorParallel() {
final CountDownLatch latch = new CountDownLatch(1);
final Mapper mapper = new PartitionMapperImpl() {
@Override
public long assess() {
return 2;
}
@Override
public List<Mapper> split(final long desiredSize) {
assertEquals(1, desiredSize);
return asList(this, this);
}
@Override
public Input create() {
return new InputImpl() {
private final AtomicBoolean done = new AtomicBoolean();
@Override
public Object next() {
try {
latch.await(1, MINUTES);
} catch (final InterruptedException e) {
Thread.interrupted();
fail();
}
return done.compareAndSet(false, true) ? Thread.currentThread().getName() : null;
}
@Override
protected Stream<Method> findMethods(final Class<? extends Annotation> marker) {
return Stream.empty();
}
};
}
@Override
protected Stream<Method> findMethods(final Class<? extends Annotation> marker) {
return Stream.empty();
}
};
latch.countDown();
final Stream<String> collect = COMPONENT_FACTORY.collect(String.class, mapper, 2, 2);
final List<String> threads = collect.collect(toList());
assertEquals(threads.toString(), 2, threads.size());
threads.forEach(n -> assertTrue(n, n.startsWith("SimpleComponentRule-pool-")));
}
Aggregations