use of java.util.concurrent.atomic.AtomicReference in project crate by crate.
the class PageDownstreamContextTest method testKillCallsDownstream.
@Test
public void testKillCallsDownstream() throws Throwable {
TestingBatchConsumer batchConsumer = new TestingBatchConsumer();
PageDownstreamContext ctx = getPageDownstreamContext(batchConsumer, PassThroughPagingIterator.oneShot(), 3);
final AtomicReference<Throwable> throwable = new AtomicReference<>();
ctx.completionFuture().whenComplete((r, t) -> {
if (t != null) {
assertTrue(throwable.compareAndSet(null, t));
} else {
fail("Expected exception");
}
});
ctx.kill(null);
assertThat(throwable.get(), instanceOf(InterruptedException.class));
expectedException.expect(InterruptedException.class);
batchConsumer.getResult();
}
use of java.util.concurrent.atomic.AtomicReference in project crate by crate.
the class ConcurrencyIntegrationTest method testInsertStatementsDoNotShareState.
@Test
public void testInsertStatementsDoNotShareState() throws Throwable {
execute("create table t1 (id int primary key, x int) with (number_of_replicas = 0)");
execute("create table t2 (id int primary key, x string) with (number_of_replicas = 0)");
execute("create table t3 (x timestamp) with (number_of_replicas = 0)");
execute("create table t4 (y string) with (number_of_replicas = 0)");
final CountDownLatch latch = new CountDownLatch(1000);
final AtomicReference<Throwable> lastThrowable = new AtomicReference<>();
String[] statements = new String[] { "insert into t1 (id, x) values (1, 10) on duplicate key update x = x + 10 ", "insert into t2 (id, x) values (1, 'bar') on duplicate key update x = 'foo' ", "insert into t3 (x) values (current_timestamp) ", "insert into t4 (y) values ('foo') " };
// run every statement 5 times, so all will fit into the executors pool
for (final String statement : statements) {
for (int i = 0; i < 5; i++) {
executor.submit(new Runnable() {
@Override
public void run() {
try {
while (latch.getCount() > 0) {
execute(statement);
latch.countDown();
}
} catch (Throwable t) {
// retry might not succeed
if (!t.getMessage().contains("version conflict")) {
lastThrowable.set(t);
}
}
}
});
}
}
latch.await();
Throwable throwable = lastThrowable.get();
if (throwable != null) {
throw throwable;
}
}
use of java.util.concurrent.atomic.AtomicReference in project crate by crate.
the class CreateTableIntegrationTest method executeCreateTableThreaded.
private void executeCreateTableThreaded(final String statement) throws Throwable {
ExecutorService executorService = Executors.newFixedThreadPool(20);
final AtomicReference<Throwable> lastThrowable = new AtomicReference<>();
for (int i = 0; i < 20; i++) {
executorService.submit(new Runnable() {
@Override
public void run() {
try {
execute(statement);
} catch (Throwable t) {
lastThrowable.set(t);
}
}
});
}
executorService.shutdown();
assertThat("executorservice did not shutdown within timeout", executorService.awaitTermination(3, TimeUnit.SECONDS), is(true));
Throwable throwable = lastThrowable.get();
if (throwable != null) {
throw throwable;
}
}
use of java.util.concurrent.atomic.AtomicReference in project crate by crate.
the class InformationSchemaQueryTest method testConcurrentInformationSchemaQueries.
@Test
public void testConcurrentInformationSchemaQueries() throws Exception {
final SQLResponse response = execute("select * from information_schema.columns " + "order by table_schema, table_name, column_name");
final CountDownLatch latch = new CountDownLatch(40);
final AtomicReference<AssertionError> lastAssertionError = new AtomicReference<>();
for (int i = 0; i < 40; i++) {
final Thread t = new Thread(new Runnable() {
@Override
public void run() {
SQLResponse resp = execute("select * from information_schema.columns " + "order by table_schema, table_name, column_name");
try {
assertThat(resp.rows(), Matchers.equalTo(response.rows()));
} catch (AssertionError e) {
lastAssertionError.set(e);
}
latch.countDown();
}
});
t.start();
}
latch.await();
AssertionError assertionError = lastAssertionError.get();
if (assertionError != null) {
throw assertionError;
}
}
use of java.util.concurrent.atomic.AtomicReference in project crate by crate.
the class InformationSchemaQueryTest method testConcurrentUnassignedShardsReferenceResolver.
@Test
public void testConcurrentUnassignedShardsReferenceResolver() throws Exception {
internalCluster().ensureAtMostNumDataNodes(1);
execute("create table t1 (col1 integer) " + "clustered into 1 shards " + "with (number_of_replicas=8)");
execute("create table t2 (col1 integer) " + "clustered into 1 shards " + "with (number_of_replicas=8)");
ensureYellow();
final SQLResponse response = execute("select * from sys.shards where table_name in ('t1', 't2') and state='UNASSIGNED' order by schema_name, table_name, id");
final CountDownLatch latch = new CountDownLatch(40);
final AtomicReference<AssertionError> lastAssertionError = new AtomicReference<>();
for (int i = 0; i < 40; i++) {
final Thread t = new Thread(new Runnable() {
@Override
public void run() {
SQLResponse resp = execute("select * from sys.shards where table_name in ('t1', 't2') and state='UNASSIGNED' order by schema_name, table_name, id");
try {
assertThat(resp.rows(), Matchers.equalTo(response.rows()));
} catch (AssertionError e) {
lastAssertionError.set(e);
}
latch.countDown();
}
});
t.start();
}
latch.await();
AssertionError assertionError = lastAssertionError.get();
if (assertionError != null) {
throw assertionError;
}
}
Aggregations