Search in sources :

Example 6 with InMemoryRouter

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

the class FrontendRestRequestServiceFactoryTest method getFrontendRestRequestServiceTest.

/**
 * Tests the instantiation of an {@link FrontendRestRequestService} instance through the
 * {@link FrontendRestRequestServiceFactory}.
 * @throws Exception
 */
@Test
public void getFrontendRestRequestServiceTest() throws Exception {
    // dud properties. server should pick up defaults
    JSONObject jsonObject = new JSONObject().put("POST", "http://uploadUrl:15158").put("GET", "http://downloadUrl:15158");
    Properties properties = new Properties();
    CommonTestUtils.populateRequiredRouterProps(properties);
    properties.setProperty(FrontendConfig.URL_SIGNER_ENDPOINTS, jsonObject.toString());
    properties.setProperty("clustermap.cluster.name", "Cluster-Name");
    properties.setProperty("clustermap.datacenter.name", "Datacenter-Name");
    properties.setProperty("clustermap.host.name", "localhost");
    VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
    FrontendRestRequestServiceFactory frontendRestRequestServiceFactory = new FrontendRestRequestServiceFactory(verifiableProperties, new MockClusterMap(), new InMemoryRouter(verifiableProperties, new MockClusterMap()), new InMemAccountService(false, true));
    RestRequestService ambryRestRequestService = frontendRestRequestServiceFactory.getRestRequestService();
    assertNotNull("No RestRequestService returned", ambryRestRequestService);
    assertEquals("Did not receive an FrontendRestRequestService instance", FrontendRestRequestService.class.getCanonicalName(), ambryRestRequestService.getClass().getCanonicalName());
}
Also used : InMemoryRouter(com.github.ambry.router.InMemoryRouter) InMemAccountService(com.github.ambry.account.InMemAccountService) RestRequestService(com.github.ambry.rest.RestRequestService) JSONObject(org.json.JSONObject) VerifiableProperties(com.github.ambry.config.VerifiableProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Example 7 with InMemoryRouter

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

the class AsyncRequestResponseHandlerFactoryTest method getFactoryTestWithBadInputTest.

/**
 * Tests instantiation of {@link AsyncRequestResponseHandlerFactory} with bad input.
 */
@Test
public void getFactoryTestWithBadInputTest() throws IOException {
    VerifiableProperties verifiableProperties = new VerifiableProperties(new Properties());
    Router router = new InMemoryRouter(verifiableProperties, new MockClusterMap());
    RestRequestService restRequestService = new MockRestRequestService(verifiableProperties, router);
    // handlerCount = 0
    try {
        new AsyncRequestResponseHandlerFactory(0, new MetricRegistry(), restRequestService);
        fail("Instantiation should have failed because response handler count is 0");
    } catch (IllegalArgumentException e) {
    // expected. Nothing to do.
    }
    // handlerCount < 0
    try {
        new AsyncRequestResponseHandlerFactory(-1, new MetricRegistry(), restRequestService);
        fail("Instantiation should have failed because response handler count is less than 0");
    } catch (IllegalArgumentException e) {
    // expected. Nothing to do.
    }
    // MetricRegistry null.
    try {
        new AsyncRequestResponseHandlerFactory(1, null, restRequestService);
        fail("Instantiation should have failed because one of the arguments was null");
    } catch (IllegalArgumentException e) {
    // expected. Nothing to do.
    }
    // handlerCount = 0
    try {
        new AsyncRequestResponseHandlerFactory(0, new MetricRegistry(), restRequestService);
        fail("Instantiation should have failed because request handler count is 0");
    } catch (IllegalArgumentException e) {
    // expected. Nothing to do.
    }
    // handlerCount < 0
    try {
        new AsyncRequestResponseHandlerFactory(-1, new MetricRegistry(), restRequestService);
        fail("Instantiation should have failed because request handler count is less than 0");
    } catch (IllegalArgumentException e) {
    // expected. Nothing to do.
    }
    // MetricRegistry null.
    try {
        new AsyncRequestResponseHandlerFactory(1, null, restRequestService);
        fail("Instantiation should have failed because one of the arguments was null");
    } catch (IllegalArgumentException e) {
    // expected. Nothing to do.
    }
    // RestRequestService null.
    try {
        new AsyncRequestResponseHandlerFactory(1, new MetricRegistry(), null);
        fail("Instantiation should have failed because one of the arguments was null");
    } catch (IllegalArgumentException e) {
    // expected. Nothing to do.
    }
}
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)

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