use of org.apache.cassandra.utils.WrappedRunnable in project cassandra by apache.
the class DebuggableThreadPoolExecutorTest method testSerialization.
@Test
public void testSerialization() {
LinkedBlockingQueue<Runnable> q = new LinkedBlockingQueue<Runnable>(1);
DebuggableThreadPoolExecutor executor = new DebuggableThreadPoolExecutor(1, Integer.MAX_VALUE, TimeUnit.MILLISECONDS, q, new NamedThreadFactory("TEST"));
WrappedRunnable runnable = new WrappedRunnable() {
public void runMayThrow() throws InterruptedException {
Thread.sleep(50);
}
};
long start = System.nanoTime();
for (int i = 0; i < 10; i++) {
executor.execute(runnable);
}
assert q.size() > 0 : q.size();
while (executor.getCompletedTaskCount() < 10) continue;
long delta = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
assert delta >= 9 * 50 : delta;
}
use of org.apache.cassandra.utils.WrappedRunnable in project eiger by wlloyd.
the class DefinitionsUpdateVerbHandler method doVerb.
/** someone sent me their data definitions */
public void doVerb(final Message message, String id) {
try {
// these are the serialized row mutations that I must apply.
// check versions at every step along the way to make sure migrations are not applied out of order.
Collection<Column> cols = MigrationManager.makeColumns(message);
for (Column col : cols) {
final UUID version = UUIDGen.getUUID(col.name());
if (version.timestamp() > Schema.instance.getVersion().timestamp()) {
final Migration m = Migration.deserialize(col.value(), message.getVersion());
assert m.getVersion().equals(version);
StageManager.getStage(Stage.MIGRATION).submit(new WrappedRunnable() {
protected void runMayThrow() throws Exception {
// check to make sure the current version is before this one.
if (Schema.instance.getVersion().timestamp() == version.timestamp())
logger.debug("Not appling (equal) " + version.toString());
else if (Schema.instance.getVersion().timestamp() > version.timestamp())
logger.debug("Not applying (before)" + version.toString());
else {
logger.debug("Applying {} from {}", m.getClass().getSimpleName(), message.getFrom());
try {
m.apply();
// update gossip, but don't contact nodes directly
m.passiveAnnounce();
} catch (ConfigurationException ex) {
// Trying to apply the same migration twice. This happens as a result of gossip.
logger.debug("Migration not applied " + ex.getMessage());
}
}
}
});
}
}
} catch (IOException ex) {
throw new IOError(ex);
}
}
use of org.apache.cassandra.utils.WrappedRunnable in project eiger by wlloyd.
the class DebuggableThreadPoolExecutorTest method testSerialization.
@Test
public void testSerialization() throws InterruptedException {
LinkedBlockingQueue<Runnable> q = new LinkedBlockingQueue<Runnable>(1);
DebuggableThreadPoolExecutor executor = new DebuggableThreadPoolExecutor(1, Integer.MAX_VALUE, TimeUnit.MILLISECONDS, q, new NamedThreadFactory("TEST"));
WrappedRunnable runnable = new WrappedRunnable() {
public void runMayThrow() throws InterruptedException {
Thread.sleep(50);
}
};
long start = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
executor.execute(runnable);
}
assert q.size() > 0 : q.size();
while (executor.getCompletedTaskCount() < 10) continue;
long delta = System.currentTimeMillis() - start;
assert delta >= 9 * 50 : delta;
}
use of org.apache.cassandra.utils.WrappedRunnable in project eiger by wlloyd.
the class TableTest method testGetRowSingleColumn.
@Test
public void testGetRowSingleColumn() throws Throwable {
final Table table = Table.open("Keyspace1");
final ColumnFamilyStore cfStore = table.getColumnFamilyStore("Standard1");
RowMutation rm = new RowMutation("Keyspace1", TEST_KEY.key);
ColumnFamily cf = ColumnFamily.create("Keyspace1", "Standard1");
cf.addColumn(column("col1", "val1", 1L));
cf.addColumn(column("col2", "val2", 1L));
cf.addColumn(column("col3", "val3", 1L));
rm.add(cf);
rm.apply();
Runnable verify = new WrappedRunnable() {
public void runMayThrow() throws Exception {
ColumnFamily cf;
cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(TEST_KEY, new QueryPath("Standard1"), ByteBufferUtil.bytes("col1")));
assertColumns(cf, "col1");
cf = cfStore.getColumnFamily(QueryFilter.getNamesFilter(TEST_KEY, new QueryPath("Standard1"), ByteBufferUtil.bytes("col3")));
assertColumns(cf, "col3");
}
};
reTest(table.getColumnFamilyStore("Standard1"), verify);
}
use of org.apache.cassandra.utils.WrappedRunnable in project eiger by wlloyd.
the class TableTest method testGetSliceFromSuperBasic.
@Test
public void testGetSliceFromSuperBasic() throws Throwable {
// tests slicing against data from one row spread across two sstables
final Table table = Table.open("Keyspace1");
final ColumnFamilyStore cfStore = table.getColumnFamilyStore("Super1");
final DecoratedKey ROW = Util.dk("row2");
RowMutation rm = new RowMutation("Keyspace1", ROW.key);
ColumnFamily cf = ColumnFamily.create("Keyspace1", "Super1");
SuperColumn sc = new SuperColumn(ByteBufferUtil.bytes("sc1"), Int32Type.instance);
sc.addColumn(new Column(getBytes(1), ByteBufferUtil.bytes("val1"), 1L));
cf.addColumn(sc);
rm.add(cf);
rm.apply();
Runnable verify = new WrappedRunnable() {
public void runMayThrow() throws Exception {
ColumnFamily cf = cfStore.getColumnFamily(ROW, new QueryPath("Super1"), ByteBufferUtil.EMPTY_BYTE_BUFFER, ByteBufferUtil.EMPTY_BYTE_BUFFER, false, 10);
assertColumns(cf, "sc1");
ByteBuffer val = cf.getColumn(ByteBufferUtil.bytes("sc1")).getSubColumn(getBytes(1)).value();
assertEquals(ByteBufferUtil.string(val), "val1");
}
};
reTest(table.getColumnFamilyStore("Standard1"), verify);
}
Aggregations