use of org.assertj.core.api.iterable.Extractor in project java-driver by datastax.
the class ThreadingOptionsTest method should_use_provided_threading_options.
/**
* Validates that when using a provided {@link ThreadingOptions} that its methods are used for creating
* executors and that its {@link ThreadingOptions#createThreadFactory(String, String)} is used for initializing
* netty resources.
*
* @test_category configuration
*/
@Test(groups = "short")
public void should_use_provided_threading_options() {
ThreadingOptions spy = Mockito.spy(threadingOptions);
Cluster cluster = createClusterBuilder().withPoolingOptions(new PoolingOptions().setConnectionsPerHost(HostDistance.LOCAL, 1, 1)).withReconnectionPolicy(new ConstantReconnectionPolicy(100)).withThreadingOptions(spy).build();
try {
String clusterName = cluster.getClusterName();
cluster.init();
// Ensure each method was invoked appropriately:
// 1) 1 time for each create*Executor.
// 2) createThreadFactory for netty executor group and timeouter.
verify(spy).createExecutor(clusterName);
verify(spy).createBlockingExecutor(clusterName);
verify(spy).createReconnectionExecutor(clusterName);
verify(spy).createScheduledTasksExecutor(clusterName);
verify(spy).createReaperExecutor(clusterName);
verify(spy).createThreadFactory(clusterName, "nio-worker");
verify(spy).createThreadFactory(clusterName, "timeouter");
cluster.connect();
// Close all connections bringing the host down, this should cause some activity on
// executor and reconnection executor.
currentClient.disableListener();
currentClient.closeConnections(CLOSE);
TestUtils.waitForDown(TestUtils.IP_PREFIX + "1", cluster);
currentClient.enableListener();
TestUtils.waitForUp(TestUtils.IP_PREFIX + "1", cluster);
Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread thread : threads) {
// all threads should use the custom factory and thus be marked daemon
if (thread.getName().startsWith(clusterName + "-" + customPrefix)) {
// all created threads should be daemon this should indicate that our custom thread factory was
// used.
assertThat(thread.isDaemon()).isTrue();
}
}
final Pattern threadNamePattern = Pattern.compile(clusterName + "-" + customPrefix + "-(.*)-0");
// Custom executor threads should be present.
// NOTE: we don't validate blocking executor since it is hard to deterministically cause it to be used.
assertThat(threads).extracting(new Extractor<Thread, String>() {
@Override
public String extract(Thread thread) {
Matcher matcher = threadNamePattern.matcher(thread.getName());
if (matcher.matches()) {
return matcher.group(1);
} else {
return thread.getName();
}
}
}).contains("nio-worker", "timeouter", "myExecutor", "myReconnection", "myScheduled-task-worker", "myConnection-reaper");
} finally {
cluster.close();
}
}
use of org.assertj.core.api.iterable.Extractor in project powermock by powermock.
the class ConstructorCallMockTransformerTest method should_provide_correct_constructor_param_and_arguments_when_cast_required.
@Test
public void should_provide_correct_constructor_param_and_arguments_when_cast_required() throws Exception {
assumeClassLoaderMode();
MockGatewaySpy.returnOnMethodCall(SUPPRESS);
final Class<?> clazz = loadWithMockClassLoader(SuperClassCallSuperConstructorWithCast.class.getName());
final Class<?> paramClass = loadWithMockClassLoader(ParameterInterface.class.getName());
final Object param = loadWithMockClassLoader(ParameterImpl.class.getName()).newInstance();
final Constructor<?> constructor = clazz.getConstructor(paramClass);
constructor.newInstance(param);
assertThatCorrectConstructorTypeProvided();
final MethodCall methodCall = MockGatewaySpy.constructorCalls().get(0);
assertThat(methodCall.args).as("Correct constructor arguments are provided").containsExactly(param);
assertThat(methodCall.sig).as("Correct constructor signature is provided").hasSize(1).extracting(new Extractor<Class<?>, Object>() {
@Override
public Object extract(final Class<?> input) {
return input.getName();
}
}).containsExactly(ParameterImpl.class.getName());
}
Aggregations