use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class HelixParticipantTest method testBadCases.
/**
* Test bad instantiation and initialization scenarios of the {@link HelixParticipant}
* @throws IOException
*/
@Test
public void testBadCases() throws IOException {
// Connect failure.
ClusterMapConfig clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
helixManagerFactory.helixManager.beBad = true;
HelixParticipant helixParticipant = new HelixParticipant(clusterMapConfig, helixManagerFactory);
try {
helixParticipant.initialize("localhost", 2200, Collections.EMPTY_LIST);
fail("Initialization should have failed");
} catch (IOException e) {
// OK
}
// Bad param during instantiation.
props.setProperty("clustermap.cluster.name", "");
clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
try {
new HelixParticipant(clusterMapConfig, helixManagerFactory);
fail("Instantiation should have failed");
} catch (IllegalStateException e) {
// OK
}
props.setProperty("clustermap.cluster.name", "HelixParticipantTestCluster");
props.setProperty("clustermap.dcs.zk.connect.strings", "");
clusterMapConfig = new ClusterMapConfig(new VerifiableProperties(props));
try {
new HelixParticipant(clusterMapConfig, helixManagerFactory);
fail("Instantiation should have failed");
} catch (IOException e) {
// OK
}
}
use of com.github.ambry.config.VerifiableProperties 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.github.ambry.config.VerifiableProperties 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.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class HelixAccountServiceTest method testBackgroundUpdater.
/**
* Tests the background updater for updating accounts from remote. During the initialization of
* {@link HelixAccountService}, its internal {@link HelixPropertyStore} will be read to first time get account data.
* Because of the background account updater, it should continuously make get calls to the {@link HelixPropertyStore},
* even no notification for account updates is received. Therefore, there will be more than 1 get calls to the
* {@link HelixPropertyStore}.
* @throws Exception
*/
@Test
public void testBackgroundUpdater() throws Exception {
helixConfigProps.setProperty(HelixAccountServiceConfig.UPDATER_POLLING_INTERVAL_MS_KEY, "1");
vHelixConfigProps = new VerifiableProperties(helixConfigProps);
storeConfig = new HelixPropertyStoreConfig(vHelixConfigProps);
String updaterThreadPrefix = UUID.randomUUID().toString();
MockHelixAccountServiceFactory mockHelixAccountServiceFactory = new MockHelixAccountServiceFactory(vHelixConfigProps, new MetricRegistry(), notifier, updaterThreadPrefix);
accountService = mockHelixAccountServiceFactory.getAccountService();
CountDownLatch latch = new CountDownLatch(1);
mockHelixAccountServiceFactory.getHelixStore(storeConfig).setReadLatch(latch);
assertEquals("Wrong number of thread for account updater.", 1, numThreadsByThisName(updaterThreadPrefix));
awaitLatchOrTimeout(latch, 100);
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class SingleKeyManagementServiceTest method testSingleKMS.
/**
* Test {@link SingleKeyManagementService#getKey(short, short)}
*/
@Test
public void testSingleKMS() throws Exception {
int[] keySizes = { 16, 32, 64, 128 };
for (int keySize : keySizes) {
String key = TestUtils.getRandomKey(keySize);
Properties props = getKMSProperties(key, DEFAULT_RANDOM_KEY_SIZE_BITS);
VerifiableProperties verifiableProperties = new VerifiableProperties((props));
KMSConfig config = new KMSConfig(verifiableProperties);
SecretKeySpec secretKeySpec = new SecretKeySpec(Hex.decode(key), config.kmsKeyGenAlgo);
KeyManagementService<SecretKeySpec> kms = new SingleKeyManagementServiceFactory(verifiableProperties, CLUSTER_NAME, REGISTRY).getKeyManagementService();
SecretKeySpec keyFromKMS = kms.getKey(Utils.getRandomShort(TestUtils.RANDOM), Utils.getRandomShort(TestUtils.RANDOM));
Assert.assertEquals("Secret key mismatch ", secretKeySpec, keyFromKMS);
}
}
Aggregations