use of com.codahale.metrics.MetricRegistry in project ambry by linkedin.
the class MessageSievingInputStreamTest method testDeletedBlobs.
private void testDeletedBlobs(short blobVersion, BlobType blobType) throws IOException, MessageFormatException {
// MessageSievingInputStream contains put records for 2 valid blobs and 1 deleted blob
// id1(put record for valid blob), id2(delete record) and id3(put record for valid blob)
ArrayList<Short> versions = new ArrayList<>();
versions.add(Message_Header_Version_V1);
if (blobVersion != Blob_Version_V1) {
versions.add(Message_Header_Version_V2);
}
try {
for (short version : versions) {
headerVersionToUse = version;
// create message stream for blob 1
StoreKey key1 = new MockId("id1");
short accountId = Utils.getRandomShort(TestUtils.RANDOM);
short containerId = Utils.getRandomShort(TestUtils.RANDOM);
BlobProperties prop1 = new BlobProperties(10, "servid1", accountId, containerId, false);
byte[] encryptionKey1 = new byte[100];
TestUtils.RANDOM.nextBytes(encryptionKey1);
byte[] usermetadata1 = new byte[1000];
TestUtils.RANDOM.nextBytes(usermetadata1);
int blobContentSize = 2000;
byte[] data1 = new byte[blobContentSize];
TestUtils.RANDOM.nextBytes(data1);
if (blobVersion == Blob_Version_V2 && blobType == BlobType.MetadataBlob) {
ByteBuffer byteBufferBlob = MessageFormatTestUtils.getBlobContentForMetadataBlob(blobContentSize);
data1 = byteBufferBlob.array();
blobContentSize = data1.length;
}
ByteBufferInputStream stream1 = new ByteBufferInputStream(ByteBuffer.wrap(data1));
MessageFormatInputStream messageFormatStream1 = (blobVersion == Blob_Version_V2) ? new PutMessageFormatInputStream(key1, ByteBuffer.wrap(encryptionKey1), prop1, ByteBuffer.wrap(usermetadata1), stream1, blobContentSize, blobType) : new PutMessageFormatBlobV1InputStream(key1, prop1, ByteBuffer.wrap(usermetadata1), stream1, blobContentSize, blobType);
MessageInfo msgInfo1 = new MessageInfo(key1, messageFormatStream1.getSize(), accountId, containerId, prop1.getCreationTimeInMs());
// create message stream for blob 2 and mark it as deleted
StoreKey key2 = new MockId("id2");
accountId = Utils.getRandomShort(TestUtils.RANDOM);
containerId = Utils.getRandomShort(TestUtils.RANDOM);
long deletionTimeMs = SystemTime.getInstance().milliseconds() + TestUtils.RANDOM.nextInt();
MessageFormatInputStream messageFormatStream2 = new DeleteMessageFormatInputStream(key2, accountId, containerId, deletionTimeMs);
MessageInfo msgInfo2 = new MessageInfo(key2, messageFormatStream2.getSize(), accountId, containerId, deletionTimeMs);
// create message stream for blob 3
StoreKey key3 = new MockId("id3");
accountId = Utils.getRandomShort(TestUtils.RANDOM);
containerId = Utils.getRandomShort(TestUtils.RANDOM);
BlobProperties prop3 = new BlobProperties(10, "servid3", accountId, containerId, false);
byte[] encryptionKey3 = new byte[100];
TestUtils.RANDOM.nextBytes(encryptionKey3);
byte[] usermetadata3 = new byte[1000];
TestUtils.RANDOM.nextBytes(usermetadata3);
blobContentSize = 2000;
byte[] data3 = new byte[blobContentSize];
TestUtils.RANDOM.nextBytes(data3);
if (blobVersion == Blob_Version_V2 && blobType == BlobType.MetadataBlob) {
ByteBuffer byteBufferBlob = MessageFormatTestUtils.getBlobContentForMetadataBlob(blobContentSize);
data3 = byteBufferBlob.array();
blobContentSize = data3.length;
}
ByteBufferInputStream stream3 = new ByteBufferInputStream(ByteBuffer.wrap(data3));
MessageFormatInputStream messageFormatStream3 = (blobVersion == Blob_Version_V2) ? new PutMessageFormatInputStream(key3, ByteBuffer.wrap(encryptionKey3), prop3, ByteBuffer.wrap(usermetadata3), stream3, blobContentSize, blobType) : new PutMessageFormatBlobV1InputStream(key3, prop3, ByteBuffer.wrap(usermetadata3), stream3, blobContentSize, blobType);
MessageInfo msgInfo3 = new MessageInfo(key3, messageFormatStream3.getSize(), accountId, containerId, prop3.getCreationTimeInMs());
// create input stream for all blob messages together
byte[] totalMessageContent = new byte[(int) messageFormatStream1.getSize() + (int) messageFormatStream2.getSize() + (int) messageFormatStream3.getSize()];
messageFormatStream1.read(totalMessageContent, 0, (int) messageFormatStream1.getSize());
messageFormatStream2.read(totalMessageContent, (int) messageFormatStream1.getSize(), (int) messageFormatStream2.getSize());
messageFormatStream3.read(totalMessageContent, (int) messageFormatStream1.getSize() + (int) messageFormatStream2.getSize(), (int) messageFormatStream3.getSize());
InputStream inputStream = new ByteBufferInputStream(ByteBuffer.wrap(totalMessageContent));
List<MessageInfo> msgInfoList = new ArrayList<MessageInfo>();
msgInfoList.add(msgInfo1);
msgInfoList.add(msgInfo2);
msgInfoList.add(msgInfo3);
MessageSievingInputStream validMessageDetectionInputStream = new MessageSievingInputStream(inputStream, msgInfoList, new MockIdFactory(), new MetricRegistry());
Assert.fail("IllegalStateException should have been thrown due to delete record ");
}
} catch (IllegalStateException e) {
Assert.assertTrue("IllegalStateException thrown as expected ", true);
}
headerVersionToUse = Message_Header_Version_V1;
}
use of com.codahale.metrics.MetricRegistry in project ambry by linkedin.
the class BlockingChannelConnectionPoolTest method startServer.
/**
* Starts up an ambry server given a port number in localhost
*
* @param port the port number over which ambry server needs to be started
* @return the {@link SocketServer} referring to ambry's instance
* @throws IOException
* @throws InterruptedException
*/
private SocketServer startServer(int port) throws IOException, InterruptedException {
Properties props = new Properties();
props.setProperty("port", "" + port);
props.setProperty("clustermap.cluster.name", "test");
props.setProperty("clustermap.datacenter.name", "dc1");
props.setProperty("clustermap.host.name", "localhost");
VerifiableProperties propverify = new VerifiableProperties(props);
NetworkConfig config = new NetworkConfig(propverify);
ArrayList<Port> ports = new ArrayList<Port>();
ports.add(new Port(port, PortType.PLAINTEXT));
ports.add(new Port(port + 1000, PortType.SSL));
SocketServer server = new SocketServer(config, serverSSLConfig1, new MetricRegistry(), ports);
server.start();
return server;
}
use of com.codahale.metrics.MetricRegistry in project ambry by linkedin.
the class BlockingChannelConnectionPoolTest method testSSLBlockingChannelConnectionPool.
// @Test
public void testSSLBlockingChannelConnectionPool() throws Exception {
Properties props = new Properties();
props.put("connectionpool.max.connections.per.port.plain.text", "5");
props.put("connectionpool.max.connections.per.port.ssl", "5");
props.put("clustermap.cluster.name", "test");
props.put("clustermap.datacenter.name", "dc1");
props.put("clustermap.host.name", "localhost");
ConnectionPool connectionPool = new BlockingChannelConnectionPool(new ConnectionPoolConfig(new VerifiableProperties(props)), sslConfig, sslEnabledClusterMapConfig, new MetricRegistry());
connectionPool.start();
CountDownLatch shouldRelease = new CountDownLatch(1);
CountDownLatch releaseComplete = new CountDownLatch(10);
AtomicReference<Exception> exception = new AtomicReference<Exception>();
Map<String, CountDownLatch> channelCount = new HashMap<String, CountDownLatch>();
channelCount.put("localhost" + 7667, new CountDownLatch(5));
channelCount.put("localhost" + 7668, new CountDownLatch(5));
channelCount.put("localhost" + 7669, new CountDownLatch(5));
Map<String, Port> channelToPortMap = new HashMap<String, Port>();
channelToPortMap.put("localhost" + 7667, new Port(7667, PortType.SSL));
channelToPortMap.put("localhost" + 7668, new Port(7668, PortType.SSL));
channelToPortMap.put("localhost" + 7669, new Port(7669, PortType.SSL));
for (int i = 0; i < 10; i++) {
ConnectionPoolThread connectionPoolThread = new ConnectionPoolThread(channelCount, channelToPortMap, connectionPool, false, shouldRelease, releaseComplete, exception);
Thread t = new Thread(connectionPoolThread);
t.start();
}
for (String channelStr : channelCount.keySet()) {
awaitCountdown(channelCount.get(channelStr), 1000, exception, "Timed out waiting for channel count to reach 5");
}
// reset
for (String channelStr : channelCount.keySet()) {
channelCount.put(channelStr, new CountDownLatch(5));
}
shouldRelease.countDown();
for (String channelStr : channelCount.keySet()) {
awaitCountdown(channelCount.get(channelStr), 1000, exception, "Timed out waiting for channel count to reach 5");
}
awaitCountdown(releaseComplete, 2000, exception, "Timed out while waiting for channels to be released");
connectionPool.shutdown();
}
use of com.codahale.metrics.MetricRegistry in project ambry by linkedin.
the class SSLBlockingChannelTest method testRenegotiation.
@Test
public void testRenegotiation() throws Exception {
BlockingChannel channel = new SSLBlockingChannel(hostName, sslPort, new MetricRegistry(), 10000, 10000, 10000, 2000, sslSocketFactory, clientSSLConfig);
sendAndReceive(channel);
sslEchoServer.renegotiate();
sendAndReceive(channel);
channel.disconnect();
}
use of com.codahale.metrics.MetricRegistry in project ambry by linkedin.
the class SSLBlockingChannelTest method testWrongPortConnection.
@Test
public void testWrongPortConnection() throws Exception {
BlockingChannel channel = new SSLBlockingChannel(hostName, sslPort + 1, new MetricRegistry(), 10000, 10000, 10000, 2000, sslSocketFactory, clientSSLConfig);
try {
// send request
channel.connect();
fail("should have thrown!");
} catch (IOException e) {
}
}
Aggregations