Search in sources :

Example 46 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class LegacySSTableTest method readSimpleTable.

private static void readSimpleTable(String legacyVersion, String pkValue) {
    logger.debug("Read simple: legacy_{}_simple", legacyVersion);
    UntypedResultSet rs;
    rs = QueryProcessor.executeInternal(String.format("SELECT val FROM legacy_tables.legacy_%s_simple WHERE pk=?", legacyVersion), pkValue);
    Assert.assertNotNull(rs);
    Assert.assertEquals(1, rs.size());
    Assert.assertEquals("foo bar baz", rs.one().getString("val"));
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 47 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class TriggersTest method assertUpdateNotExecuted.

private void assertUpdateNotExecuted(String cf, int key) {
    UntypedResultSet rs = QueryProcessor.executeInternal(String.format("SELECT * FROM %s.%s WHERE k=%s", ksName, cf, key));
    assertTrue(rs.isEmpty());
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 48 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class LocalSessionTest method loadCorruptRow.

/**
 * If there are problems with the rows we're reading out of the repair table, we should
 * do the best we can to repair them, but not refuse to startup.
 */
@Test
public void loadCorruptRow() throws Exception {
    LocalSessions sessions = new LocalSessions();
    LocalSession session = createSession();
    sessions.save(session);
    sessions = new LocalSessions();
    sessions.start();
    Assert.assertNotNull(sessions.getSession(session.sessionID));
    QueryProcessor.instance.executeInternal("DELETE participants, participants_wp FROM system.repairs WHERE parent_id=?", session.sessionID);
    sessions = new LocalSessions();
    sessions.start();
    Assert.assertNull(sessions.getSession(session.sessionID));
    UntypedResultSet res = QueryProcessor.executeInternal("SELECT * FROM system.repairs WHERE parent_id=?", session.sessionID);
    assertTrue(res.isEmpty());
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) AbstractRepairTest(org.apache.cassandra.repair.AbstractRepairTest) Test(org.junit.Test)

Example 49 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class SSTableTasksTableTest method testSelectAll.

@Test
public void testSelectAll() throws Throwable {
    createTable("CREATE TABLE %s (pk int, ck int, PRIMARY KEY (pk, ck))");
    ColumnFamilyStore cfs = getCurrentColumnFamilyStore();
    long bytesCompacted = 123;
    long bytesTotal = 123456;
    UUID compactionId = UUID.randomUUID();
    List<SSTableReader> sstables = IntStream.range(0, 10).mapToObj(i -> MockSchema.sstable(i, i * 10L, i * 10L + 9, cfs)).collect(Collectors.toList());
    CompactionInfo.Holder compactionHolder = new CompactionInfo.Holder() {

        public CompactionInfo getCompactionInfo() {
            return new CompactionInfo(cfs.metadata(), OperationType.COMPACTION, bytesCompacted, bytesTotal, compactionId, sstables);
        }

        public boolean isGlobal() {
            return false;
        }
    };
    CompactionManager.instance.active.beginCompaction(compactionHolder);
    UntypedResultSet result = execute("SELECT * FROM vts.sstable_tasks");
    assertRows(result, row(CQLTester.KEYSPACE, currentTable(), compactionId, 1.0 * bytesCompacted / bytesTotal, OperationType.COMPACTION.toString().toLowerCase(), bytesCompacted, sstables.size(), bytesTotal, CompactionInfo.Unit.BYTES.toString()));
    CompactionManager.instance.active.finishCompaction(compactionHolder);
    result = execute("SELECT * FROM vts.sstable_tasks");
    assertEmpty(result);
}
Also used : IntStream(java.util.stream.IntStream) CompactionManager(org.apache.cassandra.db.compaction.CompactionManager) BeforeClass(org.junit.BeforeClass) CQLTester(org.apache.cassandra.cql3.CQLTester) MockSchema(org.apache.cassandra.schema.MockSchema) Test(org.junit.Test) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) CompactionInfo(org.apache.cassandra.db.compaction.CompactionInfo) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) OperationType(org.apache.cassandra.db.compaction.OperationType) UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Before(org.junit.Before) UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) CompactionInfo(org.apache.cassandra.db.compaction.CompactionInfo) UUID(java.util.UUID) Test(org.junit.Test)

Example 50 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class MigrationManagerTest method addNewTable.

@Test
public void addNewTable() throws ConfigurationException {
    final String ksName = KEYSPACE1;
    final String tableName = "anewtable";
    KeyspaceMetadata original = Schema.instance.getKeyspaceMetadata(ksName);
    TableMetadata cfm = addTestTable(original.name, tableName, "A New Table");
    assertFalse(Schema.instance.getKeyspaceMetadata(ksName).tables.get(cfm.name).isPresent());
    MigrationManager.announceNewTable(cfm);
    assertTrue(Schema.instance.getKeyspaceMetadata(ksName).tables.get(cfm.name).isPresent());
    assertEquals(cfm, Schema.instance.getKeyspaceMetadata(ksName).tables.get(cfm.name).get());
    // now read and write to it.
    QueryProcessor.executeInternal(String.format("INSERT INTO %s.%s (key, col, val) VALUES (?, ?, ?)", ksName, tableName), "key0", "col0", "val0");
    // flush to exercise more than just hitting the memtable
    ColumnFamilyStore cfs = Keyspace.open(ksName).getColumnFamilyStore(tableName);
    assertNotNull(cfs);
    cfs.forceBlockingFlush();
    // and make sure we get out what we put in
    UntypedResultSet rows = QueryProcessor.executeInternal(String.format("SELECT * FROM %s.%s", ksName, tableName));
    assertRows(rows, row("key0", "col0", "val0"));
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Test(org.junit.Test)

Aggregations

UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)107 Test (org.junit.Test)35 UUID (java.util.UUID)8 ByteBuffer (java.nio.ByteBuffer)6 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)6 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)6 HashSet (java.util.HashSet)5 Mutation (org.apache.cassandra.db.Mutation)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 HashMap (java.util.HashMap)4 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)4 TableMetadata (org.apache.cassandra.schema.TableMetadata)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)3 ResultMessage (org.apache.cassandra.transport.messages.ResultMessage)3 Predicate (com.google.common.base.Predicate)2 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 ArrayList (java.util.ArrayList)2