Search in sources :

Example 11 with ThrowingConsumer

use of com.github.ambry.utils.ThrowingConsumer in project ambry by linkedin.

the class AmbryServerSecurityServiceTest method validateRequestTest.

/**
 * Tests for {@link AmbryServerSecurityService#validateRequest(RestRequest, Callback)}
 * @throws Exception
 */
@Test
public void validateRequestTest() throws Exception {
    // request is null
    TestUtils.assertException(IllegalArgumentException.class, () -> serverSecurityService.validateRequest(null).get(), null);
    // success case
    RestRequest request = new MockRestRequest(MockRestRequest.DUMMY_DATA, null);
    serverSecurityService.validateRequest(request, (r, e) -> {
        Assert.assertNull("result not null", r);
        Assert.assertNull("exception not null", e);
    });
    // service is closed
    serverSecurityService.close();
    ThrowingConsumer<ExecutionException> errorAction = e -> {
        Assert.assertTrue("Exception should have been an instance of RestServiceException", e.getCause() instanceof RestServiceException);
        RestServiceException re = (RestServiceException) e.getCause();
        Assert.assertEquals("Unexpected RestServerErrorCode (Future)", RestServiceErrorCode.ServiceUnavailable, re.getErrorCode());
    };
    TestUtils.assertException(ExecutionException.class, () -> serverSecurityService.validateRequest(request).get(), errorAction);
}
Also used : MockRestRequest(com.github.ambry.rest.MockRestRequest) ServerSecurityService(com.github.ambry.rest.ServerSecurityService) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) RestServiceErrorCode(com.github.ambry.rest.RestServiceErrorCode) ServerConfig(com.github.ambry.config.ServerConfig) Test(org.junit.Test) ThrowingConsumer(com.github.ambry.utils.ThrowingConsumer) ExecutionException(java.util.concurrent.ExecutionException) AmbryRequests(com.github.ambry.protocol.AmbryRequests) Mockito(org.mockito.Mockito) RestServiceException(com.github.ambry.rest.RestServiceException) SSLSession(javax.net.ssl.SSLSession) TestUtils(com.github.ambry.utils.TestUtils) ServerMetrics(com.github.ambry.commons.ServerMetrics) Callback(com.github.ambry.commons.Callback) Assert(org.junit.Assert) RestRequest(com.github.ambry.rest.RestRequest) RestServiceException(com.github.ambry.rest.RestServiceException) MockRestRequest(com.github.ambry.rest.MockRestRequest) RestRequest(com.github.ambry.rest.RestRequest) MockRestRequest(com.github.ambry.rest.MockRestRequest) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

RestRequest (com.github.ambry.rest.RestRequest)11 RestServiceErrorCode (com.github.ambry.rest.RestServiceErrorCode)11 RestServiceException (com.github.ambry.rest.RestServiceException)11 ThrowingConsumer (com.github.ambry.utils.ThrowingConsumer)11 MetricRegistry (com.codahale.metrics.MetricRegistry)9 RequestPath (com.github.ambry.rest.RequestPath)9 RestMethod (com.github.ambry.rest.RestMethod)9 RestResponseChannel (com.github.ambry.rest.RestResponseChannel)9 RestUtils (com.github.ambry.rest.RestUtils)9 TestUtils (com.github.ambry.utils.TestUtils)9 ExecutionException (java.util.concurrent.ExecutionException)9 Assert (org.junit.Assert)9 Test (org.junit.Test)9 FrontendConfig (com.github.ambry.config.FrontendConfig)8 VerifiableProperties (com.github.ambry.config.VerifiableProperties)8 ByteBuffer (java.nio.ByteBuffer)8 Properties (java.util.Properties)8 Account (com.github.ambry.account.Account)7 InMemAccountService (com.github.ambry.account.InMemAccountService)7 MockRestRequest (com.github.ambry.rest.MockRestRequest)7