Search in sources :

Example 36 with LoggingNotificationSystem

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();
        }
    }
}
Also used : LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) BlobProperties(com.github.ambry.messageformat.BlobProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) Test(org.junit.Test)

Example 37 with LoggingNotificationSystem

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);
        }
    }
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) BlobProperties(com.github.ambry.messageformat.BlobProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) Test(org.junit.Test)

Example 38 with LoggingNotificationSystem

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());
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) BlobProperties(com.github.ambry.messageformat.BlobProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) RouterConfig(com.github.ambry.config.RouterConfig) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) MockTime(com.github.ambry.utils.MockTime) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Example 39 with LoggingNotificationSystem

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);
        }
    }
}
Also used : Account(com.github.ambry.account.Account) PrimitiveIterator(java.util.PrimitiveIterator) ArrayList(java.util.ArrayList) AtomicReference(java.util.concurrent.atomic.AtomicReference) LongStream(java.util.stream.LongStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CountDownLatch(java.util.concurrent.CountDownLatch) Container(com.github.ambry.account.Container) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) Test(org.junit.Test)

Example 40 with LoggingNotificationSystem

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);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) Test(org.junit.Test)

Aggregations

LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)47 VerifiableProperties (com.github.ambry.config.VerifiableProperties)37 Test (org.junit.Test)33 Properties (java.util.Properties)29 BlobProperties (com.github.ambry.messageformat.BlobProperties)25 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)19 RouterConfig (com.github.ambry.config.RouterConfig)19 ArrayList (java.util.ArrayList)16 InMemAccountService (com.github.ambry.account.InMemAccountService)14 MockTime (com.github.ambry.utils.MockTime)11 ByteBufferReadableStreamChannel (com.github.ambry.commons.ByteBufferReadableStreamChannel)10 ServerErrorCode (com.github.ambry.server.ServerErrorCode)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Account (com.github.ambry.account.Account)8 Container (com.github.ambry.account.Container)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 DataNodeId (com.github.ambry.clustermap.DataNodeId)7 MockDataNodeId (com.github.ambry.clustermap.MockDataNodeId)7