use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class NettyServerTest method getNettyServer.
// helpers
// general
/**
* Gets an instance of {@link NettyServer}.
* @param properties the in-memory {@link Properties} to use.
* @return an instance of {@link NettyServer}.
* @throws InstantiationException
* @throws IOException
*/
private NettyServer getNettyServer(Properties properties) throws InstantiationException, IOException {
if (properties == null) {
// dud properties. should pick up defaults
properties = new Properties();
}
VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
final NettyConfig nettyConfig = new NettyConfig(verifiableProperties);
Map<Integer, ChannelInitializer<SocketChannel>> channelInitializers = new HashMap<>();
channelInitializers.put(nettyConfig.nettyServerPort, new NettyServerChannelInitializer(nettyConfig, NETTY_METRICS, CONNECTION_STATS_HANDLER, REQUEST_HANDLER, PUBLIC_ACCESS_LOGGER, REST_SERVER_STATE, null));
channelInitializers.put(nettyConfig.nettyServerSSLPort, new NettyServerChannelInitializer(nettyConfig, NETTY_METRICS, CONNECTION_STATS_HANDLER, REQUEST_HANDLER, PUBLIC_ACCESS_LOGGER, REST_SERVER_STATE, SSL_FACTORY));
return new NettyServer(nettyConfig, NETTY_METRICS, channelInitializers);
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class RestServerTest method startShutdownTestWithBadComponent.
/**
* Tests for correct exceptions thrown on {@link RestServer#start()}/{@link RestServer#shutdown()} with bad
* components.
* @throws Exception
*/
@Test
public void startShutdownTestWithBadComponent() throws Exception {
Properties properties = new Properties();
properties.setProperty("rest.server.nio.server.factory", MockNioServerFactory.class.getCanonicalName());
// makes MockNioServer throw exceptions.
properties.setProperty(MockNioServerFactory.IS_FAULTY_KEY, "true");
VerifiableProperties verifiableProperties = getVProps(properties);
ClusterMap clusterMap = new MockClusterMap();
NotificationSystem notificationSystem = new LoggingNotificationSystem();
RestServer server = new RestServer(verifiableProperties, clusterMap, notificationSystem, SSL_FACTORY);
try {
server.start();
fail("start() should not be successful. MockNioServer::start() would have thrown InstantiationException");
} catch (InstantiationException e) {
// nothing to do. expected.
} finally {
try {
server.shutdown();
fail("RestServer shutdown should have failed.");
} catch (RuntimeException e) {
// nothing to do. expected.
}
}
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class RestServerTest method badArgumentsTest.
// serverCreationWithBadInputTest() helpers
/**
* Tests {@link RestServer} instantiation attempts with bad input.
* @throws Exception
* @throws IOException
*/
private void badArgumentsTest() throws Exception {
// dud properties. server should pick up defaults
Properties properties = new Properties();
VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
ClusterMap clusterMap = new MockClusterMap();
NotificationSystem notificationSystem = new LoggingNotificationSystem();
try {
// no props.
new RestServer(null, clusterMap, notificationSystem, SSL_FACTORY);
fail("Properties missing, yet no exception was thrown");
} catch (IllegalArgumentException e) {
// nothing to do. expected.
}
try {
// no ClusterMap.
new RestServer(verifiableProperties, null, notificationSystem, SSL_FACTORY);
fail("ClusterMap missing, yet no exception was thrown");
} catch (IllegalArgumentException e) {
// nothing to do. expected.
}
try {
// no NotificationSystem.
new RestServer(verifiableProperties, clusterMap, null, SSL_FACTORY);
fail("NotificationSystem missing, yet no exception was thrown");
} catch (IllegalArgumentException e) {
// nothing to do. expected.
}
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class ChunkFillTest method fillChunksAndAssertSuccess.
/**
* Create a {@link PutOperation} and pass in a channel with the blobSize set by the caller; and test the chunk
* filling flow for puts.
* Note that this test is for the chunk filling flow, not for the ChunkFiller thread (which never gets exercised,
* as we do not even instantiate the {@link PutManager})
*/
private void fillChunksAndAssertSuccess() throws Exception {
VerifiableProperties vProps = getNonBlockingRouterProperties();
MockClusterMap mockClusterMap = new MockClusterMap();
RouterConfig routerConfig = new RouterConfig(vProps);
routerMetrics = new NonBlockingRouterMetrics(mockClusterMap);
ResponseHandler responseHandler = new ResponseHandler(mockClusterMap);
short accountId = Utils.getRandomShort(random);
short containerId = Utils.getRandomShort(random);
BlobProperties putBlobProperties = new BlobProperties(blobSize, "serviceId", "memberId", "contentType", false, Utils.Infinite_Time, accountId, containerId, testEncryption);
Random random = new Random();
byte[] putUserMetadata = new byte[10];
random.nextBytes(putUserMetadata);
putContent = new byte[blobSize];
random.nextBytes(putContent);
final ReadableStreamChannel putChannel = new ByteBufferReadableStreamChannel(ByteBuffer.wrap(putContent));
FutureResult<String> futureResult = new FutureResult<String>();
MockTime time = new MockTime();
MockNetworkClientFactory networkClientFactory = new MockNetworkClientFactory(vProps, null, 0, 0, 0, null, time);
if (testEncryption) {
kms = new MockKeyManagementService(new KMSConfig(vProps), TestUtils.getRandomKey(SingleKeyManagementServiceTest.DEFAULT_KEY_SIZE_CHARS));
cryptoService = new MockCryptoService(new CryptoServiceConfig(vProps));
cryptoJobHandler = new CryptoJobHandler(CryptoJobHandlerTest.DEFAULT_THREAD_COUNT);
}
MockRouterCallback routerCallback = new MockRouterCallback(networkClientFactory.getNetworkClient(), Collections.EMPTY_LIST);
PutOperation op = new PutOperation(routerConfig, routerMetrics, mockClusterMap, responseHandler, new LoggingNotificationSystem(), putUserMetadata, putChannel, futureResult, null, routerCallback, null, kms, cryptoService, cryptoJobHandler, time, putBlobProperties);
op.startReadingFromChannel();
numChunks = RouterUtils.getNumChunksForBlobAndChunkSize(blobSize, chunkSize);
compositeBuffers = new ByteBuffer[numChunks];
compositeEncryptionKeys = new ByteBuffer[numChunks];
compositeBlobIds = new BlobId[numChunks];
final AtomicReference<Exception> operationException = new AtomicReference<Exception>(null);
int chunksLeftToBeFilled = numChunks;
do {
if (testEncryption) {
int chunksPerBatch = Math.min(NonBlockingRouter.MAX_IN_MEM_CHUNKS, chunksLeftToBeFilled);
CountDownLatch onPollLatch = new CountDownLatch(chunksPerBatch);
routerCallback.setOnPollLatch(onPollLatch);
op.fillChunks();
Assert.assertTrue("Latch should have been zeroed out", onPollLatch.await(1000, TimeUnit.MILLISECONDS));
chunksLeftToBeFilled -= chunksPerBatch;
} else {
op.fillChunks();
}
// since the channel is ByteBuffer based.
for (PutOperation.PutChunk putChunk : op.putChunks) {
if (putChunk.isFree()) {
continue;
}
Assert.assertEquals("Chunk should be ready.", PutOperation.ChunkState.Ready, putChunk.getState());
ByteBuffer buf = putChunk.buf;
totalSizeWritten += buf.remaining();
compositeBuffers[putChunk.getChunkIndex()] = ByteBuffer.allocate(buf.remaining()).put(buf);
if (testEncryption) {
compositeEncryptionKeys[putChunk.getChunkIndex()] = putChunk.encryptedPerBlobKey.duplicate();
compositeBlobIds[putChunk.getChunkIndex()] = putChunk.chunkBlobId;
}
putChunk.clear();
}
} while (!op.isChunkFillingDone());
if (!testEncryption) {
Assert.assertEquals("total size written out should match the blob size", blobSize, totalSizeWritten);
}
// for encrypted path, size will be implicitly tested via assertDataIdentity
Exception exception = operationException.get();
if (exception != null) {
throw exception;
}
assertDataIdentity(mockClusterMap);
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class DeleteManagerTest method testVariousServerErrorCodesForThreeParallelism.
/**
* The parallelism is set to 3 not 9.
*
* Test the case where servers return different {@link ServerErrorCode}, and the {@link DeleteOperation}
* is able to resolve and conclude the correct {@link RouterErrorCode}. The {link ServerErrorCode} tested
* are those could be mapped to {@link RouterErrorCode#AmbryUnavailable}. The order of received responses
* is the same as defined in {@code serverErrorCodes}.
*/
@Test
public void testVariousServerErrorCodesForThreeParallelism() throws Exception {
assertCloseCleanup();
Properties props = getNonBlockingRouterProperties();
props.setProperty("router.delete.request.parallelism", "3");
VerifiableProperties vProps = new VerifiableProperties(props);
router = new NonBlockingRouter(new RouterConfig(vProps), new NonBlockingRouterMetrics(clusterMap), new MockNetworkClientFactory(vProps, mockSelectorState, MAX_PORTS_PLAIN_TEXT, MAX_PORTS_SSL, CHECKOUT_TIMEOUT_MS, serverLayout, mockTime), new LoggingNotificationSystem(), clusterMap, null, null, null, mockTime);
ServerErrorCode[] serverErrorCodes = new ServerErrorCode[9];
serverErrorCodes[0] = ServerErrorCode.Blob_Not_Found;
serverErrorCodes[1] = ServerErrorCode.Data_Corrupt;
serverErrorCodes[2] = ServerErrorCode.IO_Error;
serverErrorCodes[3] = ServerErrorCode.Partition_Unknown;
serverErrorCodes[4] = ServerErrorCode.Disk_Unavailable;
serverErrorCodes[5] = ServerErrorCode.No_Error;
serverErrorCodes[6] = ServerErrorCode.Data_Corrupt;
serverErrorCodes[7] = ServerErrorCode.Unknown_Error;
serverErrorCodes[8] = ServerErrorCode.Disk_Unavailable;
testWithErrorCodes(serverErrorCodes, partition, serverLayout, RouterErrorCode.AmbryUnavailable, deleteErrorCodeChecker);
}
Aggregations