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);
}
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();
}
Aggregations