Search in sources :

Example 16 with Mutation

use of org.apache.cassandra.db.Mutation in project cassandra by apache.

the class BatchlogManagerTest method testReplayWithNoPeers.

// CASSANRDA-9223
@Test
public void testReplayWithNoPeers() throws Exception {
    StorageService.instance.getTokenMetadata().removeEndpoint(InetAddress.getByName("127.0.0.1"));
    long initialAllBatches = BatchlogManager.instance.countAllBatches();
    long initialReplayedBatches = BatchlogManager.instance.getTotalBatchesReplayed();
    TableMetadata cfm = Keyspace.open(KEYSPACE1).getColumnFamilyStore(CF_STANDARD1).metadata();
    long timestamp = (System.currentTimeMillis() - DatabaseDescriptor.getWriteRpcTimeout() * 2) * 1000;
    UUID uuid = UUIDGen.getTimeUUID();
    // Add a batch with 10 mutations
    List<Mutation> mutations = new ArrayList<>(10);
    for (int j = 0; j < 10; j++) {
        mutations.add(new RowUpdateBuilder(cfm, FBUtilities.timestampMicros(), ByteBufferUtil.bytes(j)).clustering("name" + j).add("val", "val" + j).build());
    }
    BatchlogManager.store(Batch.createLocal(uuid, timestamp, mutations));
    assertEquals(1, BatchlogManager.instance.countAllBatches() - initialAllBatches);
    // Flush the batchlog to disk (see CASSANDRA-6822).
    Keyspace.open(SchemaConstants.SYSTEM_KEYSPACE_NAME).getColumnFamilyStore(SystemKeyspace.BATCHES).forceBlockingFlush();
    assertEquals(1, BatchlogManager.instance.countAllBatches() - initialAllBatches);
    assertEquals(0, BatchlogManager.instance.getTotalBatchesReplayed() - initialReplayedBatches);
    // Force batchlog replay and wait for it to complete.
    BatchlogManager.instance.startBatchlogReplay().get();
    // Replay should be cancelled as there are no peers in the ring.
    assertEquals(1, BatchlogManager.instance.countAllBatches() - initialAllBatches);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) RowUpdateBuilder(org.apache.cassandra.db.RowUpdateBuilder) Mutation(org.apache.cassandra.db.Mutation)

Aggregations

Mutation (org.apache.cassandra.db.Mutation)16 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)9 TableMetadata (org.apache.cassandra.schema.TableMetadata)8 UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)5 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)3 Row (org.apache.cassandra.db.rows.Row)3 DataInputBuffer (org.apache.cassandra.io.util.DataInputBuffer)3 Test (org.junit.Test)3 UUID (java.util.UUID)2 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)2 DataInputPlus (org.apache.cassandra.io.util.DataInputPlus)2 DataOutputBuffer (org.apache.cassandra.io.util.DataOutputBuffer)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 File (java.io.File)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1