use of com.github.ambry.commons.LoggingNotificationSystem in project ambry by linkedin.
the class NonBlockingRouterTest method testNonBlockingRouterFactory.
/**
* Test the {@link NonBlockingRouterFactory}
*/
@Test
public void testNonBlockingRouterFactory() throws Exception {
Properties props = getNonBlockingRouterProperties("NotInClusterMap");
VerifiableProperties verifiableProperties = new VerifiableProperties((props));
try {
router = (NonBlockingRouter) new NonBlockingRouterFactory(verifiableProperties, mockClusterMap, new LoggingNotificationSystem(), null).getRouter();
Assert.fail("NonBlockingRouterFactory instantiation should have failed because the router datacenter is not in " + "the cluster map");
} catch (IllegalStateException e) {
}
props = getNonBlockingRouterProperties("DC1");
verifiableProperties = new VerifiableProperties((props));
router = (NonBlockingRouter) new NonBlockingRouterFactory(verifiableProperties, mockClusterMap, new LoggingNotificationSystem(), null).getRouter();
assertExpectedThreadCounts(2, 1);
router.close();
assertExpectedThreadCounts(0, 0);
}
use of com.github.ambry.commons.LoggingNotificationSystem in project ambry by linkedin.
the class NonBlockingRouterTest method testRequestResponseHandlerThreadExitFlow.
/**
* Test RequestResponseHandler thread exit flow. If the RequestResponseHandlerThread exits on its own (due to a
* Throwable), then the router gets closed immediately along with the completion of all the operations.
*/
@Test
public void testRequestResponseHandlerThreadExitFlow() throws Exception {
Properties props = getNonBlockingRouterProperties("DC1");
VerifiableProperties verifiableProperties = new VerifiableProperties((props));
MockClusterMap mockClusterMap = new MockClusterMap();
MockTime mockTime = new MockTime();
router = new NonBlockingRouter(new RouterConfig(verifiableProperties), new NonBlockingRouterMetrics(mockClusterMap), new MockNetworkClientFactory(verifiableProperties, mockSelectorState, MAX_PORTS_PLAIN_TEXT, MAX_PORTS_SSL, CHECKOUT_TIMEOUT_MS, new MockServerLayout(mockClusterMap), mockTime), new LoggingNotificationSystem(), mockClusterMap, kms, cryptoService, cryptoJobHandler, mockTime);
assertExpectedThreadCounts(2, 1);
setOperationParams();
mockSelectorState.set(MockSelectorState.ThrowExceptionOnAllPoll);
Future future = router.putBlob(putBlobProperties, putUserMetadata, putChannel);
try {
while (!future.isDone()) {
mockTime.sleep(1000);
Thread.yield();
}
future.get();
Assert.fail("The operation should have failed");
} catch (ExecutionException e) {
Assert.assertEquals(RouterErrorCode.OperationTimedOut, ((RouterException) e.getCause()).getErrorCode());
}
setOperationParams();
mockSelectorState.set(MockSelectorState.ThrowThrowableOnSend);
future = router.putBlob(putBlobProperties, putUserMetadata, putChannel);
Thread requestResponseHandlerThreadRegular = TestUtils.getThreadByThisName("RequestResponseHandlerThread-0");
Thread requestResponseHandlerThreadBackground = TestUtils.getThreadByThisName("RequestResponseHandlerThread-backgroundDeleter");
if (requestResponseHandlerThreadRegular != null) {
requestResponseHandlerThreadRegular.join(NonBlockingRouter.SHUTDOWN_WAIT_MS);
}
if (requestResponseHandlerThreadBackground != null) {
requestResponseHandlerThreadBackground.join(NonBlockingRouter.SHUTDOWN_WAIT_MS);
}
try {
future.get();
Assert.fail("The operation should have failed");
} catch (ExecutionException e) {
Assert.assertEquals(RouterErrorCode.RouterClosed, ((RouterException) e.getCause()).getErrorCode());
}
assertClosed();
// Ensure that both operations failed and with the right exceptions.
Assert.assertEquals("No ChunkFiller Thread should be running after the router is closed", 0, TestUtils.numThreadsByThisName("ChunkFillerThread"));
Assert.assertEquals("No RequestResponseHandler should be running after the router is closed", 0, TestUtils.numThreadsByThisName("RequestResponseHandlerThread"));
Assert.assertEquals("All operations should have completed", 0, router.getOperationsCount());
}
use of com.github.ambry.commons.LoggingNotificationSystem in project ambry by linkedin.
the class RestServerTest method startShutdownTest.
/**
* Tests {@link RestServer#start()} and {@link RestServer#shutdown()}.
* @throws Exception
*/
@Test
public void startShutdownTest() throws Exception {
Properties properties = new Properties();
VerifiableProperties verifiableProperties = getVProps(properties);
ClusterMap clusterMap = new MockClusterMap();
NotificationSystem notificationSystem = new LoggingNotificationSystem();
RestServer server = new RestServer(verifiableProperties, clusterMap, notificationSystem, SSL_FACTORY);
server.start();
server.shutdown();
server.awaitShutdown();
}
use of com.github.ambry.commons.LoggingNotificationSystem in project ambry by linkedin.
the class RestServerTest method shutdownWithoutStartTest.
/**
* Tests for {@link RestServer#shutdown()} when {@link RestServer#start()} had not been called previously. This test
* is for cases where {@link RestServer#start()} has failed and {@link RestServer#shutdown()} needs to be run.
* @throws Exception
*/
@Test
public void shutdownWithoutStartTest() throws Exception {
Properties properties = new Properties();
VerifiableProperties verifiableProperties = getVProps(properties);
ClusterMap clusterMap = new MockClusterMap();
NotificationSystem notificationSystem = new LoggingNotificationSystem();
RestServer server = new RestServer(verifiableProperties, clusterMap, notificationSystem, SSL_FACTORY);
server.shutdown();
server.awaitShutdown();
}
use of com.github.ambry.commons.LoggingNotificationSystem in project ambry by linkedin.
the class RestServerTest method doBadFactoryClassTest.
/**
* Tests for bad factory class name for {@code configKey} in {@link RestServer}.
* @param configKey the property whose value is the bad factory class
* @throws Exception
*/
private void doBadFactoryClassTest(String configKey) throws Exception {
Properties properties = new Properties();
setMandatoryValues(properties);
// Non existent class.
properties.setProperty(configKey, "non.existent.factory");
VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
try {
new RestServer(verifiableProperties, new MockClusterMap(), new LoggingNotificationSystem(), SSL_FACTORY);
fail("Properties file contained non existent " + configKey + ", yet no exception was thrown");
} catch (ClassNotFoundException e) {
// nothing to do. expected.
}
// invalid factory class.
properties.setProperty(configKey, RestServerTest.class.getCanonicalName());
verifiableProperties = new VerifiableProperties(properties);
try {
new RestServer(verifiableProperties, new MockClusterMap(), new LoggingNotificationSystem(), SSL_FACTORY);
fail("Properties file contained invalid " + configKey + " class, yet no exception was thrown");
} catch (NullPointerException e) {
// nothing to do. expected.
}
// faulty factory class
properties.setProperty(configKey, FaultyFactory.class.getCanonicalName());
verifiableProperties = new VerifiableProperties(properties);
try {
RestServer restServer = new RestServer(verifiableProperties, new MockClusterMap(), new LoggingNotificationSystem(), SSL_FACTORY);
restServer.start();
fail("Properties file contained faulty " + configKey + " class, yet no exception was thrown");
} catch (InstantiationException e) {
// nothing to do. expected.
}
}
Aggregations