use of com.github.ambry.commons.LoggingNotificationSystem in project ambry by linkedin.
the class NonBlockingRouterTest method testMultipleScalingUnit.
/**
* Test that multiple scaling units can be instantiated, exercised and closed.
*/
@Test
public void testMultipleScalingUnit() throws Exception {
try {
final int SCALING_UNITS = 3;
Properties props = getNonBlockingRouterProperties("DC1");
props.setProperty("router.scaling.unit.count", Integer.toString(SCALING_UNITS));
setRouter(props, new MockServerLayout(mockClusterMap), new LoggingNotificationSystem());
assertExpectedThreadCounts(SCALING_UNITS + 1, SCALING_UNITS);
// Submit a few jobs so that all the scaling units get exercised.
for (int i = 0; i < SCALING_UNITS * 10; i++) {
setOperationParams();
router.putBlob(putBlobProperties, putUserMetadata, putChannel, new PutBlobOptionsBuilder().build()).get();
}
} finally {
if (router != null) {
router.close();
assertExpectedThreadCounts(0, 0);
// submission after closing should return a future that is already done.
setOperationParams();
assertClosed();
}
}
}
use of com.github.ambry.commons.LoggingNotificationSystem in project ambry by linkedin.
the class NonBlockingRouterTest method testNonBlockingRouterFactory.
/**
* Test the {@link NonBlockingRouterFactory}
*/
@Test
public void testNonBlockingRouterFactory() throws Exception {
try {
Properties props = getNonBlockingRouterProperties("NotInClusterMap");
VerifiableProperties verifiableProperties = new VerifiableProperties((props));
try {
router = (NonBlockingRouter) new NonBlockingRouterFactory(verifiableProperties, mockClusterMap, new LoggingNotificationSystem(), null, accountService).getRouter();
Assert.fail("NonBlockingRouterFactory instantiation should have failed because the router datacenter is not in " + "the cluster map");
} catch (IllegalStateException e) {
}
props = getNonBlockingRouterProperties("DC1");
verifiableProperties = new VerifiableProperties((props));
router = (NonBlockingRouter) new NonBlockingRouterFactory(verifiableProperties, mockClusterMap, new LoggingNotificationSystem(), null, accountService).getRouter();
assertExpectedThreadCounts(2, 1);
} finally {
if (router != null) {
router.close();
assertExpectedThreadCounts(0, 0);
}
}
}
use of com.github.ambry.commons.LoggingNotificationSystem in project ambry by linkedin.
the class NonBlockingRouterTest method testRequestResponseHandlerThreadExitFlow.
/**
* Test RequestResponseHandler thread exit flow. If the RequestResponseHandlerThread exits on its own (due to a
* Throwable), then the router gets closed immediately along with the completion of all the operations.
*/
@Test
public void testRequestResponseHandlerThreadExitFlow() throws Exception {
nettyByteBufLeakHelper.setDisabled(true);
Properties props = getNonBlockingRouterProperties("DC1");
VerifiableProperties verifiableProperties = new VerifiableProperties((props));
RouterConfig routerConfig = new RouterConfig(verifiableProperties);
MockClusterMap mockClusterMap = new MockClusterMap();
MockTime mockTime = new MockTime();
router = new NonBlockingRouter(routerConfig, new NonBlockingRouterMetrics(mockClusterMap, routerConfig), new MockNetworkClientFactory(verifiableProperties, mockSelectorState, MAX_PORTS_PLAIN_TEXT, MAX_PORTS_SSL, CHECKOUT_TIMEOUT_MS, new MockServerLayout(mockClusterMap), mockTime), new LoggingNotificationSystem(), mockClusterMap, kms, cryptoService, cryptoJobHandler, accountService, mockTime, MockClusterMap.DEFAULT_PARTITION_CLASS);
assertExpectedThreadCounts(2, 1);
setOperationParams();
mockSelectorState.set(MockSelectorState.ThrowExceptionOnAllPoll);
Future future = router.putBlob(putBlobProperties, putUserMetadata, putChannel, new PutBlobOptionsBuilder().build());
try {
while (!future.isDone()) {
mockTime.sleep(1000);
Thread.yield();
}
future.get();
Assert.fail("The operation should have failed");
} catch (ExecutionException e) {
Assert.assertEquals(RouterErrorCode.OperationTimedOut, ((RouterException) e.getCause()).getErrorCode());
}
setOperationParams();
mockSelectorState.set(MockSelectorState.ThrowThrowableOnSend);
future = router.putBlob(putBlobProperties, putUserMetadata, putChannel, new PutBlobOptionsBuilder().build());
Thread requestResponseHandlerThreadRegular = TestUtils.getThreadByThisName("RequestResponseHandlerThread-0");
Thread requestResponseHandlerThreadBackground = TestUtils.getThreadByThisName("RequestResponseHandlerThread-backgroundDeleter");
if (requestResponseHandlerThreadRegular != null) {
requestResponseHandlerThreadRegular.join(NonBlockingRouter.SHUTDOWN_WAIT_MS);
}
if (requestResponseHandlerThreadBackground != null) {
requestResponseHandlerThreadBackground.join(NonBlockingRouter.SHUTDOWN_WAIT_MS);
}
try {
future.get();
Assert.fail("The operation should have failed");
} catch (ExecutionException e) {
Assert.assertEquals(RouterErrorCode.RouterClosed, ((RouterException) e.getCause()).getErrorCode());
}
assertClosed();
// Ensure that both operations failed and with the right exceptions.
Assert.assertEquals("No ChunkFiller Thread should be running after the router is closed", 0, TestUtils.numThreadsByThisName("ChunkFillerThread"));
Assert.assertEquals("No RequestResponseHandler should be running after the router is closed", 0, TestUtils.numThreadsByThisName("RequestResponseHandlerThread"));
Assert.assertEquals("All operations should have completed", 0, router.getOperationsCount());
}
use of com.github.ambry.commons.LoggingNotificationSystem in project ambry by linkedin.
the class NonBlockingRouterTest method testStitchGetUpdateDelete.
/**
* Test that stitched blobs are usable by the other router methods.
* @throws Exception
*/
@Test
public void testStitchGetUpdateDelete() throws Exception {
try {
AtomicReference<CountDownLatch> deletesDoneLatch = new AtomicReference<>();
Set<String> deletedBlobs = ConcurrentHashMap.newKeySet();
LoggingNotificationSystem deleteTrackingNotificationSystem = new LoggingNotificationSystem() {
@Override
public void onBlobDeleted(String blobId, String serviceId, Account account, Container container) {
deletedBlobs.add(blobId);
deletesDoneLatch.get().countDown();
}
};
setRouter(getNonBlockingRouterProperties("DC1"), new MockServerLayout(mockClusterMap), deleteTrackingNotificationSystem);
for (int intermediateChunkSize : new int[] { maxPutChunkSize, maxPutChunkSize / 2 }) {
for (LongStream chunkSizeStream : new LongStream[] { RouterTestHelpers.buildValidChunkSizeStream(3 * intermediateChunkSize, intermediateChunkSize), RouterTestHelpers.buildValidChunkSizeStream(3 * intermediateChunkSize + random.nextInt(intermediateChunkSize - 1) + 1, intermediateChunkSize) }) {
// Upload data chunks
ByteArrayOutputStream stitchedContentStream = new ByteArrayOutputStream();
List<ChunkInfo> chunksToStitch = new ArrayList<>();
PrimitiveIterator.OfLong chunkSizeIter = chunkSizeStream.iterator();
while (chunkSizeIter.hasNext()) {
long chunkSize = chunkSizeIter.nextLong();
setOperationParams((int) chunkSize, TTL_SECS);
String blobId = router.putBlob(putBlobProperties, putUserMetadata, putChannel, new PutBlobOptionsBuilder().chunkUpload(true).maxUploadSize(PUT_CONTENT_SIZE).build()).get(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
long expirationTime = Utils.addSecondsToEpochTime(putBlobProperties.getCreationTimeInMs(), putBlobProperties.getTimeToLiveInSeconds());
chunksToStitch.add(new ChunkInfo(blobId, chunkSize, expirationTime));
stitchedContentStream.write(putContent);
}
byte[] expectedContent = stitchedContentStream.toByteArray();
// Stitch the chunks together
setOperationParams(0, TTL_SECS / 2);
String stitchedBlobId = router.stitchBlob(putBlobProperties, putUserMetadata, chunksToStitch).get(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
// Fetch the stitched blob
GetBlobResult getBlobResult = router.getBlob(stitchedBlobId, new GetBlobOptionsBuilder().build()).get(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
assertTrue("Blob properties must be the same", RouterTestHelpers.arePersistedFieldsEquivalent(putBlobProperties, getBlobResult.getBlobInfo().getBlobProperties()));
assertEquals("Unexpected blob size", expectedContent.length, getBlobResult.getBlobInfo().getBlobProperties().getBlobSize());
assertArrayEquals("User metadata must be the same", putUserMetadata, getBlobResult.getBlobInfo().getUserMetadata());
RouterTestHelpers.compareContent(expectedContent, null, getBlobResult.getBlobDataChannel());
// TtlUpdate the blob.
router.updateBlobTtl(stitchedBlobId, "update-service", Utils.Infinite_Time).get(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
// Ensure that TTL was updated on the metadata blob and all data chunks
Set<String> allBlobIds = chunksToStitch.stream().map(ChunkInfo::getBlobId).collect(Collectors.toSet());
allBlobIds.add(stitchedBlobId);
assertTtl(router, allBlobIds, Utils.Infinite_Time);
// Delete and ensure that all stitched chunks are deleted
deletedBlobs.clear();
deletesDoneLatch.set(new CountDownLatch(chunksToStitch.size() + 1));
router.deleteBlob(stitchedBlobId, "delete-service").get(AWAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
TestUtils.awaitLatchOrTimeout(deletesDoneLatch.get(), AWAIT_TIMEOUT_MS);
assertEquals("Metadata chunk and all data chunks should be deleted", allBlobIds, deletedBlobs);
}
}
} finally {
if (router != null) {
router.close();
assertExpectedThreadCounts(0, 0);
}
}
}
use of com.github.ambry.commons.LoggingNotificationSystem in project ambry by linkedin.
the class CloudRouterTest method testCloudRouterFactory.
/**
* Test the {@link CloudRouterFactory}
*/
@Test
public void testCloudRouterFactory() throws Exception {
Properties props = getNonBlockingRouterProperties("NotInClusterMap");
VerifiableProperties verifiableProperties = new VerifiableProperties((props));
try {
router = (NonBlockingRouter) new CloudRouterFactory(verifiableProperties, mockClusterMap, new LoggingNotificationSystem(), null, accountService).getRouter();
Assert.fail("NonBlockingRouterFactory instantiation should have failed because the router datacenter is not in " + "the cluster map");
} catch (IllegalStateException e) {
}
props = getNonBlockingRouterProperties("DC1");
verifiableProperties = new VerifiableProperties((props));
router = (NonBlockingRouter) new CloudRouterFactory(verifiableProperties, mockClusterMap, new LoggingNotificationSystem(), null, accountService).getRouter();
assertExpectedThreadCounts(2, 1);
router.close();
assertExpectedThreadCounts(0, 0);
}
Aggregations