use of com.emc.storageos.coordinator.common.impl.ZkConnection in project coprhd-controller by CoprHD.
the class UserInfoHelperTest method setup.
@Before
public void setup() throws Exception {
List<URI> uri = new ArrayList<URI>();
uri.add(URI.create(_coordinatorServer));
ZkConnection connection = new ZkConnection();
connection.setServer(uri);
connection.build();
_coordinatorClient.setZkConnection(connection);
_coordinatorClient.start();
String envVar = System.getenv(USER_WRONG_DOMAIN_CONFIG);
if (StringUtils.isNotBlank(envVar)) {
user_in_wrong_domain = envVar;
}
envVar = System.getenv(USER_DOESNT_EXIST_CONFIG);
if (StringUtils.isNotBlank(envVar)) {
user_doesnt_exist = envVar;
}
envVar = System.getenv(EXISTING_USER_CONFIG);
if (StringUtils.isNotBlank(envVar)) {
existing_user = envVar;
}
envVar = System.getenv(EXISTING_USER_NUM_OF_GROUPS_CONFIG);
if (StringUtils.isNotBlank(envVar)) {
try {
num_of_groups = Integer.parseInt(envVar);
} catch (NumberFormatException e) {
num_of_groups = 3;
}
}
userInfoHelper = new UserInfoHelper(_coordinatorClient);
}
use of com.emc.storageos.coordinator.common.impl.ZkConnection in project coprhd-controller by CoprHD.
the class PasswordServiceTest method getCoordinatorClient.
private CoordinatorClient getCoordinatorClient() throws Exception {
DummyCoordinatorClient client = new DummyCoordinatorClient();
ZkConnection zkConn = new ZkConnection();
List<URI> uris = new ArrayList();
uris.add(new URI("coordinator://localhost:2181"));
zkConn.setServer(uris);
zkConn.setTimeoutMs(10000);
zkConn.build();
client.setZkConnection(zkConn);
return client;
}
use of com.emc.storageos.coordinator.common.impl.ZkConnection in project coprhd-controller by CoprHD.
the class DistributedDoubleBarrierTest method testLeaveTimeout.
/**
* Test return value of leave() in case of timeout
*
* If any one members doesn't leave correctly, the leave should return false.
* In this test 5 threads enter a barrier at a time and then the first one leaves within timeout. Another one keeps sleeping.
* Then Worker1's leave should return false, and all other workers leave with false as well
*/
@Test
public void testLeaveTimeout() throws Exception {
final Timing timing = new Timing(2, TimeUnit.SECONDS);
final AtomicInteger count = new AtomicInteger(0);
final ExecutorService service = Executors.newCachedThreadPool();
final List<Future<Void>> futures = Lists.newArrayList();
Future<Void> worker1 = service.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
ZkConnection zkConnection = createConnection(60 * 1000);
CuratorFramework client = zkConnection.curator();
try {
zkConnection.connect();
DistributedDoubleBarrier barrier = new DistributedDoubleBarrier(client, "/barrier/testLeaveTimeout", QTY);
Assert.assertTrue("Return value of enter() should be true", barrier.enter(timing.seconds(), TimeUnit.SECONDS));
count.incrementAndGet();
log.info("Leaving with timeout {} seconds", timing.seconds());
Assert.assertFalse("Return value of leave() should be false", barrier.leave(timing.seconds(), TimeUnit.SECONDS));
log.info("Left with timeout");
count.decrementAndGet();
// keep the ZK connection until all other workers exit
Thread.sleep(timing.seconds() * 5 * 1000);
} finally {
CloseableUtils.closeQuietly(client);
}
return null;
}
});
futures.add(worker1);
for (int i = 1; i < QTY; ++i) {
Future<Void> worker = service.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
ZkConnection zkConnection = createConnection(60 * 1000);
CuratorFramework client = zkConnection.curator();
try {
zkConnection.connect();
DistributedDoubleBarrier barrier = new DistributedDoubleBarrier(client, "/barrier/testLeaveTimeout", QTY);
Assert.assertTrue("Return value of enter() shoud be true", barrier.enter(timing.seconds(), TimeUnit.SECONDS));
count.incrementAndGet();
Thread.sleep(timing.seconds() * 1000);
log.info("Leaving with timeout {} seconds", timing.seconds());
Assert.assertFalse("Return value of leave() should be false", barrier.leave(timing.seconds(), TimeUnit.SECONDS));
count.decrementAndGet();
log.info("Left with timeout");
// keep the ZK connection until all other workers exit
Thread.sleep(timing.seconds() * 1000);
} finally {
CloseableUtils.closeQuietly(client);
}
return null;
}
});
futures.add(worker);
}
for (Future<Void> f : futures) {
f.get();
}
Assert.assertEquals("enter/leave count", count.get(), 0);
}
use of com.emc.storageos.coordinator.common.impl.ZkConnection in project coprhd-controller by CoprHD.
the class DistributedDoubleBarrierTest method testOverSubscribed.
/**
* Test case port from Apache Curator
*/
@Test
public void testOverSubscribed() throws Exception {
final Timing timing = new Timing();
ZkConnection zkConnection = createConnection(10 * 1000);
CuratorFramework client = zkConnection.curator();
ExecutorService service = Executors.newCachedThreadPool();
ExecutorCompletionService<Void> completionService = new ExecutorCompletionService<Void>(service);
try {
client.start();
final Semaphore semaphore = new Semaphore(0);
final CountDownLatch latch = new CountDownLatch(1);
for (int i = 0; i < (QTY + 1); ++i) {
completionService.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
DistributedDoubleBarrier barrier = new DistributedDoubleBarrier(client, "/barrier/testOverSubscribed", QTY) {
@Override
protected List<String> getChildrenForEntering() throws Exception {
semaphore.release();
Assert.assertTrue(timing.awaitLatch(latch));
return super.getChildrenForEntering();
}
};
Assert.assertTrue(barrier.enter(timing.seconds(), TimeUnit.SECONDS));
Assert.assertTrue(barrier.leave(timing.seconds(), TimeUnit.SECONDS));
return null;
}
});
}
// wait until all QTY+1 barriers are trying to enter
Assert.assertTrue(semaphore.tryAcquire(QTY + 1, timing.seconds(), TimeUnit.SECONDS));
latch.countDown();
for (int i = 0; i < (QTY + 1); ++i) {
// to check for assertions
completionService.take().get();
}
} finally {
service.shutdown();
CloseableUtils.closeQuietly(client);
}
}
use of com.emc.storageos.coordinator.common.impl.ZkConnection in project coprhd-controller by CoprHD.
the class ZkSimulator method connectClient.
/**
* Connects to Zookeeper server
*
* @return The instance of CoordinatorClient
* @throws IOException
*/
private CoordinatorClient connectClient() throws IOException {
CoordinatorClientImpl client = new CoordinatorClientImpl();
ZkConnection conn = new ZkConnection();
URI zkUri = URI.create(String.format("coordinator://localhost:%s", config.getClientPortAddress().getPort()));
conn.setServer(Arrays.asList(zkUri));
conn.setTimeoutMs(10 * 1000);
conn.setSiteIdFile("build/data/zk/siteIdFile");
log.info("Connecting with coordinator service...");
conn.build();
log.info("Connecting with coordinator service.");
client.setZkConnection(conn);
CoordinatorClientInetAddressMap inetAddressMap = new CoordinatorClientInetAddressMap();
inetAddressMap.setNodeId("standalone");
inetAddressMap.setDualInetAddress(DualInetAddress.fromAddress("127.0.0.1"));
inetAddressMap.setCoordinatorClient(client);
inetAddressMap.setControllerNodeIPLookupMap(new HashMap<String, DualInetAddress>());
client.setInetAddessLookupMap(inetAddressMap);
client.setSysSvcName("syssvc");
client.setSysSvcVersion("1");
client.setVdcShortId("vdc1");
Properties properties = new Properties();
properties.setProperty(BackupConstants.BACKUP_MAX_MANUAL_COPIES, "5");
client.setDefaultProperties(properties);
FileInputStream is = new FileInputStream(ovfPropsLocation);
Properties ovfProps = new Properties();
ovfProps.load(is);
is.close();
client.setOvfProperties(ovfProps);
client.start();
return client;
}
Aggregations