Search in sources :

Example 1 with InMemoryRouter

use of com.github.ambry.router.InMemoryRouter in project ambry by linkedin.

the class AmbryBlobStorageServiceFactoryTest method getAmbryBlobStorageServiceFactoryWithBadInputTest.

/**
 * Tests instantiation of {@link AmbryBlobStorageServiceFactory} with bad input.
 * @throws Exception
 */
@Test
public void getAmbryBlobStorageServiceFactoryWithBadInputTest() throws Exception {
    // dud properties. server should pick up defaults
    Properties properties = new Properties();
    VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
    ClusterMap clusterMap = new MockClusterMap();
    RestResponseHandler restResponseHandler = new MockRestRequestResponseHandler();
    Router router = new InMemoryRouter(verifiableProperties, clusterMap);
    // VerifiableProperties null.
    try {
        new AmbryBlobStorageServiceFactory(null, clusterMap, restResponseHandler, router, new MockNotifier());
        fail("Instantiation should have failed because one of the arguments was null");
    } catch (IllegalArgumentException e) {
    // expected. Nothing to do.
    }
    // ClusterMap null.
    try {
        new AmbryBlobStorageServiceFactory(verifiableProperties, null, restResponseHandler, router, new MockNotifier());
        fail("Instantiation should have failed because one of the arguments was null");
    } catch (IllegalArgumentException e) {
    // expected. Nothing to do.
    }
    // RestResponseHandler null.
    try {
        new AmbryBlobStorageServiceFactory(verifiableProperties, clusterMap, null, router, new MockNotifier());
        fail("Instantiation should have failed because one of the arguments was null");
    } catch (IllegalArgumentException e) {
    // expected. Nothing to do.
    }
    // Router null.
    try {
        new AmbryBlobStorageServiceFactory(verifiableProperties, clusterMap, restResponseHandler, null, new MockNotifier());
        fail("Instantiation should have failed because one of the arguments was null");
    } catch (IllegalArgumentException e) {
    // expected. Nothing to do.
    }
}
Also used : ClusterMap(com.github.ambry.clustermap.ClusterMap) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) InMemoryRouter(com.github.ambry.router.InMemoryRouter) MockNotifier(com.github.ambry.account.MockNotifier) RestResponseHandler(com.github.ambry.rest.RestResponseHandler) VerifiableProperties(com.github.ambry.config.VerifiableProperties) InMemoryRouter(com.github.ambry.router.InMemoryRouter) Router(com.github.ambry.router.Router) MockRestRequestResponseHandler(com.github.ambry.rest.MockRestRequestResponseHandler) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Example 2 with InMemoryRouter

use of com.github.ambry.router.InMemoryRouter in project ambry by linkedin.

the class FrontendRestRequestServiceFactoryTest method getFrontendRestRequestServiceFactoryWithBadInputTest.

/**
 * Tests instantiation of {@link FrontendRestRequestServiceFactory} with bad input.
 * @throws Exception
 */
@Test
public void getFrontendRestRequestServiceFactoryWithBadInputTest() throws Exception {
    // dud properties. server should pick up defaults
    Properties properties = new Properties();
    VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
    ClusterMap clusterMap = new MockClusterMap();
    Router router = new InMemoryRouter(verifiableProperties, clusterMap);
    AccountService accountService = new InMemAccountService(false, true);
    // VerifiableProperties null.
    try {
        new FrontendRestRequestServiceFactory(null, clusterMap, router, accountService);
        fail("Instantiation should have failed because VerifiableProperties was null");
    } catch (NullPointerException e) {
    // expected. Nothing to do.
    }
    // ClusterMap null.
    try {
        new FrontendRestRequestServiceFactory(verifiableProperties, null, router, accountService);
        fail("Instantiation should have failed because ClusterMap was null");
    } catch (NullPointerException e) {
    // expected. Nothing to do.
    }
    // Router null.
    try {
        new FrontendRestRequestServiceFactory(verifiableProperties, clusterMap, null, accountService);
        fail("Instantiation should have failed because Router was null");
    } catch (NullPointerException e) {
    // expected. Nothing to do.
    }
    // AccountService null.
    try {
        new FrontendRestRequestServiceFactory(verifiableProperties, clusterMap, router, null);
        fail("Instantiation should have failed because AccountService was null");
    } catch (NullPointerException e) {
    // expected. Nothing to do.
    }
}
Also used : ClusterMap(com.github.ambry.clustermap.ClusterMap) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) InMemoryRouter(com.github.ambry.router.InMemoryRouter) InMemAccountService(com.github.ambry.account.InMemAccountService) VerifiableProperties(com.github.ambry.config.VerifiableProperties) InMemoryRouter(com.github.ambry.router.InMemoryRouter) Router(com.github.ambry.router.Router) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) AccountService(com.github.ambry.account.AccountService) InMemAccountService(com.github.ambry.account.InMemAccountService) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Example 3 with InMemoryRouter

use of com.github.ambry.router.InMemoryRouter in project ambry by linkedin.

the class BadRestRequest method startRequestResponseHandler.

/**
 * Sets up all the tests by providing a started {@link AsyncRequestResponseHandler} for their use.
 * @throws InstantiationException
 * @throws IOException
 */
@BeforeClass
public static void startRequestResponseHandler() throws InstantiationException, IOException {
    verifiableProperties = new VerifiableProperties(new Properties());
    router = new InMemoryRouter(verifiableProperties, new MockClusterMap());
    restRequestService = new MockRestRequestService(verifiableProperties, router);
    asyncRequestResponseHandler = new AsyncRequestResponseHandler(new RequestResponseHandlerMetrics(new MetricRegistry()), 5, restRequestService);
    restRequestService.setupResponseHandler(asyncRequestResponseHandler);
    restRequestService.start();
    asyncRequestResponseHandler.start();
}
Also used : InMemoryRouter(com.github.ambry.router.InMemoryRouter) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) BeforeClass(org.junit.BeforeClass)

Example 4 with InMemoryRouter

use of com.github.ambry.router.InMemoryRouter in project ambry by linkedin.

the class AsyncRequestResponseHandlerFactoryTest method getAsyncRequestResponseHandlerTest.

/**
 * Tests the instantiation of an {@link AsyncRequestResponseHandler} instance through the
 * {@link AsyncRequestResponseHandlerFactory}.
 * @throws InstantiationException
 */
@Test
public void getAsyncRequestResponseHandlerTest() throws InstantiationException, IOException {
    Properties properties = new Properties();
    VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
    Router router = new InMemoryRouter(verifiableProperties, new MockClusterMap());
    RestRequestService restRequestService = new MockRestRequestService(verifiableProperties, router);
    AsyncRequestResponseHandlerFactory handlerFactory = new AsyncRequestResponseHandlerFactory(1, new MetricRegistry(), restRequestService);
    // Get response handler.
    RestResponseHandler restResponseHandler = handlerFactory.getRestResponseHandler();
    assertNotNull("No RestResponseHandler returned", restResponseHandler);
    assertEquals("Did not receive an AsyncRequestResponseHandler instance", AsyncRequestResponseHandler.class.getCanonicalName(), restResponseHandler.getClass().getCanonicalName());
    // Get request handler.
    RestRequestHandler restRequestHandler = handlerFactory.getRestRequestHandler();
    assertNotNull("No RestRequestHandler returned", restRequestHandler);
    assertEquals("Did not receive an AsyncRequestResponseHandler instance", AsyncRequestResponseHandler.class.getCanonicalName(), restRequestHandler.getClass().getCanonicalName());
    // make sure they are same instance
    assertEquals("Instances of AsyncRequestResponseHandler are not the same", restResponseHandler, restRequestHandler);
    // make sure the instance starts and shuts down OK.
    restRequestHandler.start();
    restRequestHandler.shutdown();
}
Also used : InMemoryRouter(com.github.ambry.router.InMemoryRouter) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) InMemoryRouter(com.github.ambry.router.InMemoryRouter) Router(com.github.ambry.router.Router) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Example 5 with InMemoryRouter

use of com.github.ambry.router.InMemoryRouter in project ambry by linkedin.

the class AmbryBlobStorageServiceFactoryTest method getAmbryBlobStorageServiceTest.

/**
 * Tests the instantiation of an {@link AmbryBlobStorageService} instance through the
 * {@link AmbryBlobStorageServiceFactory}.
 * @throws Exception
 */
@Test
public void getAmbryBlobStorageServiceTest() throws Exception {
    // dud properties. server should pick up defaults
    Properties properties = new Properties();
    VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
    AmbryBlobStorageServiceFactory ambryBlobStorageServiceFactory = new AmbryBlobStorageServiceFactory(verifiableProperties, new MockClusterMap(), new MockRestRequestResponseHandler(), new InMemoryRouter(verifiableProperties, new MockClusterMap()), new MockNotifier());
    BlobStorageService ambryBlobStorageService = ambryBlobStorageServiceFactory.getBlobStorageService();
    assertNotNull("No BlobStorageService returned", ambryBlobStorageService);
    assertEquals("Did not receive an AmbryBlobStorageService instance", AmbryBlobStorageService.class.getCanonicalName(), ambryBlobStorageService.getClass().getCanonicalName());
}
Also used : InMemoryRouter(com.github.ambry.router.InMemoryRouter) MockNotifier(com.github.ambry.account.MockNotifier) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MockRestRequestResponseHandler(com.github.ambry.rest.MockRestRequestResponseHandler) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) BlobStorageService(com.github.ambry.rest.BlobStorageService) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Aggregations

MockClusterMap (com.github.ambry.clustermap.MockClusterMap)7 VerifiableProperties (com.github.ambry.config.VerifiableProperties)7 InMemoryRouter (com.github.ambry.router.InMemoryRouter)7 Properties (java.util.Properties)7 Test (org.junit.Test)6 Router (com.github.ambry.router.Router)4 MetricRegistry (com.codahale.metrics.MetricRegistry)3 InMemAccountService (com.github.ambry.account.InMemAccountService)2 MockNotifier (com.github.ambry.account.MockNotifier)2 ClusterMap (com.github.ambry.clustermap.ClusterMap)2 MockRestRequestResponseHandler (com.github.ambry.rest.MockRestRequestResponseHandler)2 AccountService (com.github.ambry.account.AccountService)1 BlobStorageService (com.github.ambry.rest.BlobStorageService)1 RestRequestService (com.github.ambry.rest.RestRequestService)1 RestResponseHandler (com.github.ambry.rest.RestResponseHandler)1 JSONObject (org.json.JSONObject)1 BeforeClass (org.junit.BeforeClass)1