cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adelap...@apache.org
Subject [5/9] cassandra git commit: Merge branch 'cassandra-2.2' into cassandra-3.0
Date Wed, 10 May 2017 10:47:39 GMT
Merge branch 'cassandra-2.2' into cassandra-3.0


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/aa181927
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/aa181927
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/aa181927

Branch: refs/heads/cassandra-3.11
Commit: aa181927cbfb51ccf991d78a7eb5803fa62dd408
Parents: 0f118a9 486b82a
Author: adelapena <a.penya.garcia@gmail.com>
Authored: Wed May 10 11:13:47 2017 +0100
Committer: adelapena <a.penya.garcia@gmail.com>
Committed: Wed May 10 11:13:47 2017 +0100

----------------------------------------------------------------------
 .../validation/entities/SecondaryIndexTest.java | 42 ++++++++++++++++++++
 1 file changed, 42 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/aa181927/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
index 8376652,e3616f6..64bd967
--- a/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
+++ b/test/unit/org/apache/cassandra/cql3/validation/entities/SecondaryIndexTest.java
@@@ -1160,59 -846,108 +1160,101 @@@ public class SecondaryIndexTest extend
      }
  
      @Test
 -    public void testIndexOnRegularColumnWithPartitionWithoutRows() throws Throwable
 +    public void testIndexOnPartitionKeyWithStaticColumnAndNoRows() throws Throwable
      {
 -        createTable("CREATE TABLE %s (pk int, c int, s int static, v int, PRIMARY KEY(pk,
c))");
 -        createIndex("CREATE INDEX ON %s (v)");
 -        execute("INSERT INTO %s (pk, c, s, v) VALUES (?, ?, ?, ?)", 1, 1, 9, 1);
 -        execute("INSERT INTO %s (pk, c, s, v) VALUES (?, ?, ?, ?)", 1, 2, 9, 2);
 -        execute("INSERT INTO %s (pk, s) VALUES (?, ?)", 2, 9);
 -        execute("INSERT INTO %s (pk, c, s, v) VALUES (?, ?, ?, ?)", 3, 1, 9, 1);
 -        flush();
 -        execute("DELETE FROM %s WHERE pk = ? and c = ?", 3, 1);
 -        assertRows(execute("SELECT * FROM %s WHERE v = ?", 1),
 -                   row(1, 1, 9, 1));
 +        createTable("CREATE TABLE %s (pk1 int, pk2 int, c int, s int static, v int, PRIMARY
KEY((pk1, pk2), c))");
 +        createIndex("CREATE INDEX ON %s (pk2)");
 +        execute("INSERT INTO %s (pk1, pk2, c, s, v) VALUES (?, ?, ?, ?, ?)", 1, 1, 1, 9,
1);
 +        execute("INSERT INTO %s (pk1, pk2, c, s, v) VALUES (?, ?, ?, ?, ?)", 1, 1, 2, 9,
2);
 +        execute("INSERT INTO %s (pk1, pk2, s) VALUES (?, ?, ?)", 2, 1, 9);
 +        execute("INSERT INTO %s (pk1, pk2, c, s, v) VALUES (?, ?, ?, ?, ?)", 3, 1, 1, 9,
1);
 +
 +        assertRows(execute("SELECT * FROM %s WHERE pk2 = ?", 1),
 +                   row(2, 1, null, 9, null),
 +                   row(1, 1, 1, 9, 1),
 +                   row(1, 1, 2, 9, 2),
 +                   row(3, 1, 1, 9, 1));
 +
 +        execute("UPDATE %s SET s=?, v=? WHERE pk1=? AND pk2=? AND c=?", 9, 1, 1, 10, 2);
 +        assertRows(execute("SELECT * FROM %s WHERE pk2 = ?", 10), row(1, 10, 2, 9, 1));
 +
 +        execute("UPDATE %s SET s=? WHERE pk1=? AND pk2=?", 9, 1, 20);
 +        assertRows(execute("SELECT * FROM %s WHERE pk2 = ?", 20), row(1, 20, null, 9, null));
      }
  
+     @Test
+     public void testIndexOnPartitionKeyInsertExpiringColumn() throws Throwable
+     {
+         createTable("CREATE TABLE %s (k1 int, k2 int, a int, b int, PRIMARY KEY ((k1, k2)))");
+         createIndex("CREATE INDEX on %s(k1)");
+         execute("INSERT INTO %s (k1, k2, a, b) VALUES (1, 2, 3, 4)");
+         assertRows(execute("SELECT * FROM %s WHERE k1 = 1"), row(1, 2, 3, 4));
+         execute("UPDATE %s USING TTL 1 SET b = 10 WHERE k1 = 1 AND k2 = 2");
+         Thread.sleep(1000);
+         assertRows(execute("SELECT * FROM %s WHERE k1 = 1"), row(1, 2, 3, null));
+     }
+ 
+     @Test
+     public void testIndexOnClusteringKeyInsertExpiringColumn() throws Throwable
+     {
+         createTable("CREATE TABLE %s (pk int, ck int, a int, b int, PRIMARY KEY (pk, ck))");
+         createIndex("CREATE INDEX on %s(ck)");
+         execute("INSERT INTO %s (pk, ck, a, b) VALUES (1, 2, 3, 4)");
+         assertRows(execute("SELECT * FROM %s WHERE ck = 2"), row(1, 2, 3, 4));
+         execute("UPDATE %s USING TTL 1 SET b = 10 WHERE pk = 1 AND ck = 2");
+         Thread.sleep(1000);
+         assertRows(execute("SELECT * FROM %s WHERE ck = 2"), row(1, 2, 3, null));
+     }
+ 
+     @Test
+     public void testIndexOnRegularColumnInsertExpiringColumn() throws Throwable
+     {
+         createTable("CREATE TABLE %s (pk int, ck int, a int, b int, PRIMARY KEY (pk, ck))");
+         createIndex("CREATE INDEX on %s(a)");
+         execute("INSERT INTO %s (pk, ck, a, b) VALUES (1, 2, 3, 4)");
+         assertRows(execute("SELECT * FROM %s WHERE a = 3"), row(1, 2, 3, 4));
+ 
+         execute("UPDATE %s USING TTL 1 SET b = 10 WHERE pk = 1 AND ck = 2");
+         Thread.sleep(1000);
+         assertRows(execute("SELECT * FROM %s WHERE a = 3"), row(1, 2, 3, null));
+ 
+         execute("UPDATE %s USING TTL 1 SET a = 5 WHERE pk = 1 AND ck = 2");
+         Thread.sleep(1000);
+         assertEmpty(execute("SELECT * FROM %s WHERE a = 3"));
+         assertEmpty(execute("SELECT * FROM %s WHERE a = 5"));
+     }
+ 
 -    /**
 -     * Custom index used to test the behavior of the system when the index is not ready.
 -     * As Custom indices cannot by <code>PerColumnSecondaryIndex</code> we use
a <code>PerRowSecondaryIndex</code>
 -     * to avoid the check but return a <code>CompositesSearcher</code>.
 -     */
 -    public static class IndexBlockingOnInitialization extends PerRowSecondaryIndex
 +    private ResultMessage.Prepared prepareStatement(String cql, boolean forThrift)
      {
 -        private volatile CountDownLatch latch = new CountDownLatch(1);
 -
 -        @Override
 -        public void index(ByteBuffer rowKey, ColumnFamily cf)
 -        {
 -            try
 -            {
 -                latch.await();
 -            }
 -            catch (InterruptedException e)
 -            {
 -                Thread.interrupted();
 -            }
 -        }
 -
 -        @Override
 -        public void delete(DecoratedKey key, Group opGroup)
 -        {
 -        }
 +        return QueryProcessor.prepare(String.format(cql, KEYSPACE, currentTable()),
 +                                      ClientState.forInternalCalls(),
 +                                      forThrift);
 +    }
  
 -        @Override
 -        public void init()
 -        {
 -        }
 +    private void validateCell(Cell cell, ColumnDefinition def, ByteBuffer val, long timestamp)
 +    {
 +        assertNotNull(cell);
 +        assertEquals(0, def.type.compare(cell.value(), val));
 +        assertEquals(timestamp, cell.timestamp());
 +    }
  
 -        @Override
 -        public void reload()
 -        {
 -        }
 +    private static void assertColumnValue(int expected, String name, Row row, CFMetaData
cfm)
 +    {
 +        ColumnDefinition col = cfm.getColumnDefinition(new ColumnIdentifier(name, true));
 +        AbstractType<?> type = col.type;
 +        assertEquals(expected, type.compose(row.getCell(col).value()));
 +    }
  
 -        @Override
 -        public void validateOptions() throws ConfigurationException
 -        {
 -        }
 +    /**
 +     * <code>CassandraIndex</code> that blocks during the initialization.
 +     */
 +    public static class IndexBlockingOnInitialization extends CustomCassandraIndex
 +    {
 +        private final CountDownLatch latch = new CountDownLatch(1);
  
 -        @Override
 -        public String getIndexName()
 +        public IndexBlockingOnInitialization(ColumnFamilyStore baseCfs, IndexMetadata indexDef)
          {
 -            return "testIndex";
 +            super(baseCfs, indexDef);
          }
  
          @Override


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Mime
View raw message