use of com.nearinfinity.honeycomb.mysql.HandlerProxy in project honeycomb by altamiracorp.
the class ITUtils method startProxyActionConcurrently.
/**
* Start concurrency number of actions concurrently and at the same time. This
* method ensures that the actions are started at the same time, and they are
* not being blocked in a thread pool. Obviously, this uses concurrency
* number of threads simultaneously so use caution as thread starvation
* deadlock can occur with high concurrency levels.
*
* @param concurrency Number of handler proxies to run the action against, concurrently
* @param setup Action to be run on each proxy before starting concurrent actions
* @param action Action to be run concurrently and in sync with other proxies
* @param cleanup Action to be run to cleanup proxy
* @param factory HandlerProxyFactory to supply proxies to be run concurrently
* @throws InterruptedException
*/
public static void startProxyActionConcurrently(int concurrency, final ProxyRunnable setup, final ProxyRunnable action, final ProxyRunnable cleanup, final HandlerProxyFactory factory) throws InterruptedException {
final ExecutorService executor = Executors.newCachedThreadPool();
final CountDownLatch ready = new CountDownLatch(concurrency);
final CountDownLatch start = new CountDownLatch(1);
final CountDownLatch done = new CountDownLatch(concurrency);
for (int i = 0; i < concurrency; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
HandlerProxy proxy = factory.createHandlerProxy();
setup.run(proxy);
ready.countDown();
try {
start.await();
action.run(proxy);
} catch (InterruptedException e) {
System.out.println("Interuppted");
Thread.currentThread().interrupt();
}
cleanup.run(proxy);
done.countDown();
}
});
}
ready.await();
start.countDown();
done.await();
}
use of com.nearinfinity.honeycomb.mysql.HandlerProxy in project honeycomb by altamiracorp.
the class RowOperationsIT method testUpdateNullRows.
@Test
public void testUpdateNullRows() {
HandlerProxy proxy = factory.createHandlerProxy();
List<ColumnSchema> columns = Lists.newArrayList();
List<IndexSchema> indices = Lists.newArrayList();
columns.add(ColumnSchema.builder(TestConstants.COLUMN1, ColumnType.LONG).build());
TableSchema schema = new TableSchema(columns, indices);
String tableName = AdapterType.HBASE.getName() + "/t1";
int iterations = 10;
proxy.createTable(tableName, schema.serialize(), 0);
proxy.openTable(tableName);
Row row = new Row(Maps.<String, ByteBuffer>newHashMap(), TestConstants.ZERO_UUID);
List<Row> rows = new ArrayList<Row>();
for (int j = 0; j < 50; j++) {
for (int i = 0; i < iterations; i++) {
proxy.insertRow(row.serialize());
}
proxy.flush();
proxy.startTableScan();
for (int i = 0; i < iterations; i++) {
Row deserialized = Row.deserialize(proxy.getNextRow());
deserialized.getRecords().put(TestConstants.COLUMN1, ITUtils.encodeValue(0));
rows.add(deserialized);
}
proxy.endScan();
for (Row r : rows) {
proxy.updateRow(r.serialize(), r.serialize());
}
proxy.flush();
rows.clear();
proxy.startTableScan();
for (int i = 0; i < iterations; i++) {
byte[] bytes = proxy.getNextRow();
assertNotNull(bytes);
assertThat(Row.deserialize(bytes).getRecords().get(TestConstants.COLUMN1), equalTo(ITUtils.encodeValue(0)));
}
assertNull(proxy.getNextRow());
proxy.endScan();
proxy.truncateTable();
}
proxy.closeTable();
proxy.dropTable(tableName);
}
Aggregations