Search in sources :

Example 21 with ResponseParts

use of com.github.ambry.rest.NettyClient.ResponseParts in project ambry by linkedin.

the class FrontendIntegrationTest method getClusterMapSnapshotTest.

/**
 * Tests the handling of {@link Operations#GET_CLUSTER_MAP_SNAPSHOT} requests.
 * @throws Exception
 */
@Test
public void getClusterMapSnapshotTest() throws Exception {
    FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, Operations.GET_CLUSTER_MAP_SNAPSHOT, Unpooled.buffer(0));
    ResponseParts responseParts = nettyClient.sendRequest(httpRequest, null, null).get();
    HttpResponse response = getHttpResponse(responseParts);
    assertEquals("Unexpected response status", HttpResponseStatus.OK, response.status());
    verifyTrackingHeaders(response);
    ByteBuffer content = getContent(responseParts.queue, HttpUtil.getContentLength(response));
    JSONObject expected = CLUSTER_MAP.getSnapshot();
    JSONObject actual = new JSONObject(new String(content.array()));
    // remove timestamps because they may differ
    expected.remove(ClusterMapSnapshotConstants.TIMESTAMP_MS);
    actual.remove(ClusterMapSnapshotConstants.TIMESTAMP_MS);
    assertEquals("Snapshot does not match expected", expected.toString(), actual.toString());
    // test a failure to ensure that it goes through the exception path
    String msg = TestUtils.getRandomString(10);
    CLUSTER_MAP.setExceptionOnSnapshot(new RuntimeException(msg));
    httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, Operations.GET_CLUSTER_MAP_SNAPSHOT, Unpooled.buffer(0));
    responseParts = nettyClient.sendRequest(httpRequest, null, null).get();
    response = getHttpResponse(responseParts);
    assertEquals("Unexpected response status", HttpResponseStatus.INTERNAL_SERVER_ERROR, response.status());
    verifyTrackingHeaders(response);
    assertNoContent(responseParts.queue, 1);
    CLUSTER_MAP.setExceptionOnSnapshot(null);
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) JSONObject(org.json.JSONObject) HttpResponse(io.netty.handler.codec.http.HttpResponse) ResponseParts(com.github.ambry.rest.NettyClient.ResponseParts) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 22 with ResponseParts

use of com.github.ambry.rest.NettyClient.ResponseParts in project ambry by linkedin.

the class FrontendIntegrationTest method disableUndeleteTest.

/**
 * Test when the undelete is disabled.
 */
@Test
public void disableUndeleteTest() throws Exception {
    assumeTrue(!enableUndeleteTested);
    enableUndeleteTested = true;
    File trustStoreFile = File.createTempFile("truststore", ".jks");
    trustStoreFile.deleteOnExit();
    VerifiableProperties vprop = buildFrontendVProps(trustStoreFile, false, PLAINTEXT_SERVER_PORT + 100, SSL_SERVER_PORT + 100);
    RestServer ambryRestServer = new RestServer(vprop, CLUSTER_MAP, new LoggingNotificationSystem(), SSLFactory.getNewInstance(new SSLConfig(vprop)));
    ambryRestServer.start();
    NettyClient plaintextNettyClient = new NettyClient("localhost", PLAINTEXT_SERVER_PORT + 100, null);
    NettyClient sslNettyClient = new NettyClient("localhost", SSL_SERVER_PORT + 100, SSLFactory.getNewInstance(new SSLConfig(SSL_CLIENT_VERIFIABLE_PROPS)));
    NettyClient nettyClient = useSSL ? sslNettyClient : plaintextNettyClient;
    String blobId = "randomblobid";
    HttpHeaders headers = new DefaultHttpHeaders();
    headers.set(RestUtils.Headers.BLOB_ID, addClusterPrefix ? "/" + CLUSTER_NAME + blobId : blobId);
    headers.set(RestUtils.Headers.SERVICE_ID, "updateBlobTtlAndVerify");
    FullHttpRequest httpRequest = buildRequest(HttpMethod.PUT, "/" + Operations.UNDELETE, headers, null);
    ResponseParts responseParts = nettyClient.sendRequest(httpRequest, null, null).get();
    HttpResponse response = getHttpResponse(responseParts);
    assertEquals("Unexpected response status", HttpResponseStatus.BAD_REQUEST, response.status());
    plaintextNettyClient.close();
    sslNettyClient.close();
    ambryRestServer.shutdown();
}
Also used : RestServer(com.github.ambry.rest.RestServer) SSLConfig(com.github.ambry.config.SSLConfig) NettyClient(com.github.ambry.rest.NettyClient) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) VerifiableProperties(com.github.ambry.config.VerifiableProperties) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) HttpResponse(io.netty.handler.codec.http.HttpResponse) ResponseParts(com.github.ambry.rest.NettyClient.ResponseParts) File(java.io.File) Test(org.junit.Test)

Aggregations

ResponseParts (com.github.ambry.rest.NettyClient.ResponseParts)22 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)21 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)21 HttpResponse (io.netty.handler.codec.http.HttpResponse)18 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)15 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)15 ByteBuffer (java.nio.ByteBuffer)11 Test (org.junit.Test)9 Container (com.github.ambry.account.Container)5 HttpRequest (io.netty.handler.codec.http.HttpRequest)5 Account (com.github.ambry.account.Account)4 HttpPostRequestEncoder (io.netty.handler.codec.http.multipart.HttpPostRequestEncoder)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 NettyConfig (com.github.ambry.config.NettyConfig)2 ByteRange (com.github.ambry.router.ByteRange)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 JSONObject (org.json.JSONObject)2 ClusterMap (com.github.ambry.clustermap.ClusterMap)1 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)1