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 startShutdownTestWithReporterFactory.
/**
* Tests {@link RestServer#start()} and {@link RestServer#shutdown()} with a custom {@link JmxReporter} factory.
* @throws Exception
*/
@Test
public void startShutdownTestWithReporterFactory() throws Exception {
Properties properties = new Properties();
VerifiableProperties verifiableProperties = getVProps(properties);
ClusterMap clusterMap = new MockClusterMap();
NotificationSystem notificationSystem = new LoggingNotificationSystem();
ObjectNameFactory spyObjectNameFactory = spy(new DefaultObjectNameFactory());
Function<MetricRegistry, JmxReporter> reporterFactory = reporter -> JmxReporter.forRegistry(reporter).createsObjectNamesWith(spyObjectNameFactory).build();
RestServer server = new RestServer(verifiableProperties, clusterMap, notificationSystem, SSL_FACTORY, Collections.emptyList(), reporterFactory);
server.start();
// check that the custom ObjectNameFactory specified in reporterFactory was used.
verify(spyObjectNameFactory, atLeastOnce()).createName(anyString(), anyString(), anyString());
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 (NoSuchMethodException 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.
}
}
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 NonBlockingRouterTest method testBadCallbackForUpdateTtl.
/**
* Test that a bad user defined callback will not crash the router or the manager.
* @throws Exception
*/
@Test
public void testBadCallbackForUpdateTtl() throws Exception {
try {
MockServerLayout serverLayout = new MockServerLayout(mockClusterMap);
setRouter(getNonBlockingRouterProperties("DC1"), serverLayout, new LoggingNotificationSystem());
setOperationParams();
String blobId = router.putBlob(putBlobProperties, putUserMetadata, putChannel, new PutBlobOptionsBuilder().build()).get(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
putChannel = new ByteBufferReadableStreamChannel(ByteBuffer.wrap(putContent));
String blobIdCheck = router.putBlob(putBlobProperties, putUserMetadata, putChannel, new PutBlobOptionsBuilder().build()).get(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
testWithErrorCodes(Collections.singletonMap(ServerErrorCode.No_Error, 9), serverLayout, null, expectedError -> {
final CountDownLatch callbackCalled = new CountDownLatch(1);
router.updateBlobTtl(blobId, null, Utils.Infinite_Time, (result, exception) -> {
callbackCalled.countDown();
throw new RuntimeException("Throwing an exception in the user callback");
}, null).get(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
assertTrue("Callback not called.", callbackCalled.await(10, TimeUnit.MILLISECONDS));
assertEquals("All operations should be finished.", 0, router.getOperationsCount());
assertTrue("Router should not be closed", router.isOpen());
assertTtl(router, Collections.singleton(blobId), Utils.Infinite_Time);
// Test that TtlUpdateManager is still functional
router.updateBlobTtl(blobIdCheck, null, Utils.Infinite_Time).get(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
assertTtl(router, Collections.singleton(blobIdCheck), Utils.Infinite_Time);
});
} finally {
if (router != null) {
router.close();
}
}
}
Aggregations