use of com.github.ambry.commons.LoggingNotificationSystem in project ambry by linkedin.
the class PutOperationTest method testHandleResponseWithServerErrors.
/**
* Test PUT operation that handles ServerErrorCode = Temporarily_Disabled and Replica_Unavailable
* @throws Exception
*/
@Test
public void testHandleResponseWithServerErrors() throws Exception {
int numChunks = routerConfig.routerMaxInMemPutChunks + 1;
BlobProperties blobProperties = new BlobProperties(-1, "serviceId", "memberId", "contentType", false, Utils.Infinite_Time, Utils.getRandomShort(TestUtils.RANDOM), Utils.getRandomShort(TestUtils.RANDOM), false, null, null, null);
byte[] userMetadata = new byte[10];
byte[] content = new byte[chunkSize * numChunks];
random.nextBytes(content);
ReadableStreamChannel channel = new ByteBufferReadableStreamChannel(ByteBuffer.wrap(content));
PutOperation op = PutOperation.forUpload(routerConfig, routerMetrics, mockClusterMap, new LoggingNotificationSystem(), new InMemAccountService(true, false), userMetadata, channel, PutBlobOptions.DEFAULT, new FutureResult<>(), null, new RouterCallback(new MockNetworkClient(), new ArrayList<>()), null, null, null, null, time, blobProperties, MockClusterMap.DEFAULT_PARTITION_CLASS, quotaChargeCallback);
op.startOperation();
List<RequestInfo> requestInfos = new ArrayList<>();
requestRegistrationCallback.setRequestsToSend(requestInfos);
// fill chunks would end up filling the maximum number of PutChunks.
op.fillChunks();
// poll to populate request
op.poll(requestRegistrationCallback);
// make 1st request of first chunk encounter Temporarily_Disabled
mockServer.setServerErrorForAllRequests(ServerErrorCode.Temporarily_Disabled);
ResponseInfo responseInfo = getResponseInfo(requestInfos.get(0));
PutResponse putResponse = responseInfo.getError() == null ? PutResponse.readFrom(new NettyByteBufDataInputStream(responseInfo.content())) : null;
op.handleResponse(responseInfo, putResponse);
responseInfo.release();
PutOperation.PutChunk putChunk = op.getPutChunks().get(0);
SimpleOperationTracker operationTracker = (SimpleOperationTracker) putChunk.getOperationTrackerInUse();
Assert.assertEquals("Disabled count should be 1", 1, operationTracker.getDisabledCount());
Assert.assertEquals("Disabled count should be 0", 0, operationTracker.getFailedCount());
// make 2nd request of first chunk encounter Replica_Unavailable
mockServer.setServerErrorForAllRequests(ServerErrorCode.Replica_Unavailable);
responseInfo = getResponseInfo(requestInfos.get(1));
putResponse = responseInfo.getError() == null ? PutResponse.readFrom(new NettyByteBufDataInputStream(responseInfo.content())) : null;
op.handleResponse(responseInfo, putResponse);
responseInfo.release();
putChunk = op.getPutChunks().get(0);
Assert.assertEquals("Failure count should be 1", 1, ((SimpleOperationTracker) putChunk.getOperationTrackerInUse()).getFailedCount());
mockServer.resetServerErrors();
// Release all the other requests
requestInfos.forEach(info -> info.getRequest().release());
}
use of com.github.ambry.commons.LoggingNotificationSystem in project ambry by linkedin.
the class AmbryServerTest method testAmbryServerWithReporterFactory.
/**
* Test starting and shutting down the server with a custom {@link JmxReporter} factory.
* @throws Exception
*/
@Test
public void testAmbryServerWithReporterFactory() throws Exception {
ClusterAgentsFactory clusterAgentsFactory = new MockClusterAgentsFactory(false, false, 1, 1, 1);
ObjectNameFactory spyObjectNameFactory = spy(new DefaultObjectNameFactory());
Function<MetricRegistry, JmxReporter> reporterFactory = reporter -> JmxReporter.forRegistry(reporter).createsObjectNamesWith(spyObjectNameFactory).build();
DataNodeId dataNodeId = clusterAgentsFactory.getClusterMap().getDataNodeIds().get(0);
Properties props = new Properties();
props.setProperty("host.name", dataNodeId.getHostname());
props.setProperty("port", Integer.toString(dataNodeId.getPort()));
props.setProperty("clustermap.cluster.name", "test");
props.setProperty("clustermap.datacenter.name", "DC1");
props.setProperty("clustermap.host.name", dataNodeId.getHostname());
AmbryServer ambryServer = new AmbryServer(new VerifiableProperties(props), clusterAgentsFactory, null, new LoggingNotificationSystem(), SystemTime.getInstance(), reporterFactory);
ambryServer.startup();
verify(spyObjectNameFactory, atLeastOnce()).createName(anyString(), anyString(), anyString());
ambryServer.shutdown();
}
Aggregations