Search in sources :

Example 1 with WrappedRunnable

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;
}
Also used : WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Test(org.junit.Test)

Example 2 with WrappedRunnable

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);
    }
}
Also used : WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) ConfigurationException(org.apache.cassandra.config.ConfigurationException) IOError(java.io.IOError) Migration(org.apache.cassandra.db.migration.Migration) IOException(java.io.IOException) UUID(java.util.UUID) IOException(java.io.IOException) ConfigurationException(org.apache.cassandra.config.ConfigurationException)

Example 3 with WrappedRunnable

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;
}
Also used : WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Test(org.junit.Test)

Example 4 with WrappedRunnable

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);
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) Test(org.junit.Test)

Example 5 with WrappedRunnable

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);
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) WrappedRunnable(org.apache.cassandra.utils.WrappedRunnable) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Aggregations

WrappedRunnable (org.apache.cassandra.utils.WrappedRunnable)21 Test (org.junit.Test)12 QueryPath (org.apache.cassandra.db.filter.QueryPath)7 ByteBuffer (java.nio.ByteBuffer)3 IOException (java.io.IOException)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 Row (com.datastax.driver.core.Row)1 NoHostAvailableException (com.datastax.driver.core.exceptions.NoHostAvailableException)1 WriteTimeoutException (com.datastax.driver.core.exceptions.WriteTimeoutException)1 File (java.io.File)1 IOError (java.io.IOError)1 InetAddress (java.net.InetAddress)1 DecimalFormat (java.text.DecimalFormat)1 NumberFormat (java.text.NumberFormat)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 Future (java.util.concurrent.Future)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 CRC32 (java.util.zip.CRC32)1