use of com.cinchapi.concourse.ConnectionPool in project concourse by cinchapi.
the class CON669 method testConsistencyOfWideReadsWithConcurrentWrites.
@Test
public void testConsistencyOfWideReadsWithConcurrentWrites() throws Exception {
int threads = 10;
ConnectionPool connections = ConnectionPool.newCachedConnectionPool(SERVER_HOST, SERVER_PORT, "admin", "admin");
try {
client.set("count", 1L, 1);
AtomicBoolean done = new AtomicBoolean(false);
AtomicBoolean passed = new AtomicBoolean(true);
Thread reader = new Thread(() -> {
while (!done.get()) {
Concourse con = connections.request();
try {
Assert.assertFalse(con.select(1).get("count").isEmpty());
} catch (Exception e) {
e.printStackTrace();
passed.set(false);
} finally {
connections.release(con);
}
}
});
reader.start();
for (int i = 0; i < threads; ++i) {
Thread t = new Thread(() -> {
while (!done.get()) {
Concourse con = connections.request();
try {
long expected = (long) con.select(1).get("count").iterator().next();
con.verifyAndSwap("count", expected, 1, Time.now());
} catch (Exception e) {
e.printStackTrace();
passed.set(false);
} finally {
connections.release(con);
}
}
});
t.start();
}
Threads.sleep(3000);
done.set(true);
Assert.assertTrue(passed.get());
} finally {
while (!connections.isClosed()) {
try {
connections.close();
} catch (IllegalStateException e) {
Threads.sleep(100);
}
}
}
}
Aggregations