Merge branch 'cassandra-2.2' into cassandra-3.0

Conflicts:
        test/unit/org/apache/cassandra/Util.java
        test/unit/org/apache/cassandra/concurrent/WaitQueueTest.java


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

Branch: refs/heads/trunk
Commit: bf4740867a4a9d54d06c8c91802e02793b2bde2f
Parents: ace28c9 7636a6b
Author: Benedict Elliott Smith <[email protected]>
Authored: Thu Aug 6 14:51:27 2015 +0200
Committer: Benedict Elliott Smith <[email protected]>
Committed: Thu Aug 6 14:51:27 2015 +0200

----------------------------------------------------------------------
 test/unit/org/apache/cassandra/Util.java        | 24 ++++++++++----------
 .../cassandra/concurrent/WaitQueueTest.java     |  2 +-
 2 files changed, 13 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/bf474086/test/unit/org/apache/cassandra/Util.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/Util.java
index 7efe6f4,da81aaa..358168f
--- a/test/unit/org/apache/cassandra/Util.java
+++ b/test/unit/org/apache/cassandra/Util.java
@@@ -250,283 -333,67 +250,283 @@@ public class Uti
          assert thrown : exception.getName() + " not received";
      }
  
 -    public static QueryFilter namesQueryFilter(ColumnFamilyStore cfs, 
DecoratedKey key)
 +    public static AbstractReadCommandBuilder.SinglePartitionBuilder 
cmd(ColumnFamilyStore cfs, Object... partitionKey)
      {
 -        SortedSet<CellName> s = new TreeSet<CellName>(cfs.getComparator());
 -        return QueryFilter.getNamesFilter(key, cfs.name, s, 
System.currentTimeMillis());
 +        return new AbstractReadCommandBuilder.SinglePartitionBuilder(cfs, 
makeKey(cfs.metadata, partitionKey));
      }
  
 -    public static QueryFilter namesQueryFilter(ColumnFamilyStore cfs, 
DecoratedKey key, String... names)
 +    public static AbstractReadCommandBuilder.PartitionRangeBuilder 
cmd(ColumnFamilyStore cfs)
      {
 -        SortedSet<CellName> s = new TreeSet<CellName>(cfs.getComparator());
 -        for (String str : names)
 -            s.add(cellname(str));
 -        return QueryFilter.getNamesFilter(key, cfs.name, s, 
System.currentTimeMillis());
 +        return new AbstractReadCommandBuilder.PartitionRangeBuilder(cfs);
      }
  
 -    public static QueryFilter namesQueryFilter(ColumnFamilyStore cfs, 
DecoratedKey key, CellName... names)
 +    static DecoratedKey makeKey(CFMetaData metadata, Object... partitionKey)
      {
 -        SortedSet<CellName> s = new TreeSet<CellName>(cfs.getComparator());
 -        for (CellName n : names)
 -            s.add(n);
 -        return QueryFilter.getNamesFilter(key, cfs.name, s, 
System.currentTimeMillis());
 +        if (partitionKey.length == 1 && partitionKey[0] instanceof 
DecoratedKey)
 +            return (DecoratedKey)partitionKey[0];
 +
 +        ByteBuffer key = 
CFMetaData.serializePartitionKey(metadata.getKeyValidatorAsClusteringComparator().make(partitionKey));
 +        return metadata.decorateKey(key);
      }
  
 -    public static NamesQueryFilter namesFilter(ColumnFamilyStore cfs, 
String... names)
 +    public static void assertEmptyUnfiltered(ReadCommand command)
      {
 -        SortedSet<CellName> s = new TreeSet<CellName>(cfs.getComparator());
 -        for (String str : names)
 -            s.add(cellname(str));
 -        return new NamesQueryFilter(s);
 +        try (ReadOrderGroup orderGroup = command.startOrderGroup(); 
UnfilteredPartitionIterator iterator = command.executeLocally(orderGroup))
 +        {
 +            if (iterator.hasNext())
 +            {
 +                try (UnfilteredRowIterator partition = iterator.next())
 +                {
 +                    throw new AssertionError("Expected no results for query " 
+ command.toCQLString() + " but got key " + 
command.metadata().getKeyValidator().getString(partition.partitionKey().getKey()));
 +                }
 +            }
 +        }
      }
  
 -    public static String string(ByteBuffer bb)
 +    public static void assertEmpty(ReadCommand command)
      {
 -        try
 +        try (ReadOrderGroup orderGroup = command.startOrderGroup(); 
PartitionIterator iterator = command.executeInternal(orderGroup))
 +        {
 +            if (iterator.hasNext())
 +            {
 +                try (RowIterator partition = iterator.next())
 +                {
 +                    throw new AssertionError("Expected no results for query " 
+ command.toCQLString() + " but got key " + 
command.metadata().getKeyValidator().getString(partition.partitionKey().getKey()));
 +                }
 +            }
 +        }
 +    }
 +
 +    public static List<ArrayBackedPartition> getAllUnfiltered(ReadCommand 
command)
 +    {
 +        List<ArrayBackedPartition> results = new ArrayList<>();
 +        try (ReadOrderGroup orderGroup = command.startOrderGroup(); 
UnfilteredPartitionIterator iterator = command.executeLocally(orderGroup))
 +        {
 +            while (iterator.hasNext())
 +            {
 +                try (UnfilteredRowIterator partition = iterator.next())
 +                {
 +                    results.add(ArrayBackedPartition.create(partition));
 +                }
 +            }
 +        }
 +        return results;
 +    }
 +
 +    public static List<FilteredPartition> getAll(ReadCommand command)
 +    {
 +        List<FilteredPartition> results = new ArrayList<>();
 +        try (ReadOrderGroup orderGroup = command.startOrderGroup(); 
PartitionIterator iterator = command.executeInternal(orderGroup))
 +        {
 +            while (iterator.hasNext())
 +            {
 +                try (RowIterator partition = iterator.next())
 +                {
 +                    results.add(FilteredPartition.create(partition));
 +                }
 +            }
 +        }
 +        return results;
 +    }
 +
 +    public static Row getOnlyRowUnfiltered(ReadCommand cmd)
 +    {
 +        try (ReadOrderGroup orderGroup = cmd.startOrderGroup(); 
UnfilteredPartitionIterator iterator = cmd.executeLocally(orderGroup))
 +        {
 +            assert iterator.hasNext() : "Expecting one row in one partition 
but got nothing";
 +            try (UnfilteredRowIterator partition = iterator.next())
 +            {
 +                assert !iterator.hasNext() : "Expecting a single partition 
but got more";
 +
 +                assert partition.hasNext() : "Expecting one row in one 
partition but got an empty partition";
 +                Row row = ((Row)partition.next());
 +                assert !partition.hasNext() : "Expecting a single row but got 
more";
 +                return row;
 +            }
 +        }
 +    }
 +
 +    public static Row getOnlyRow(ReadCommand cmd)
 +    {
 +        try (ReadOrderGroup orderGroup = cmd.startOrderGroup(); 
PartitionIterator iterator = cmd.executeInternal(orderGroup))
 +        {
 +            assert iterator.hasNext() : "Expecting one row in one partition 
but got nothing";
 +            try (RowIterator partition = iterator.next())
 +            {
 +                assert !iterator.hasNext() : "Expecting a single partition 
but got more";
 +                assert partition.hasNext() : "Expecting one row in one 
partition but got an empty partition";
 +                Row row = partition.next();
 +                assert !partition.hasNext() : "Expecting a single row but got 
more";
 +                return row;
 +            }
 +        }
 +    }
 +
 +    public static ArrayBackedPartition getOnlyPartitionUnfiltered(ReadCommand 
cmd)
 +    {
 +        try (ReadOrderGroup orderGroup = cmd.startOrderGroup(); 
UnfilteredPartitionIterator iterator = cmd.executeLocally(orderGroup))
 +        {
 +            assert iterator.hasNext() : "Expecting a single partition but got 
nothing";
 +            try (UnfilteredRowIterator partition = iterator.next())
 +            {
 +                assert !iterator.hasNext() : "Expecting a single partition 
but got more";
 +                return ArrayBackedPartition.create(partition);
 +            }
 +        }
 +    }
 +
 +    public static FilteredPartition getOnlyPartition(ReadCommand cmd)
 +    {
 +        try (ReadOrderGroup orderGroup = cmd.startOrderGroup(); 
PartitionIterator iterator = cmd.executeInternal(orderGroup))
 +        {
 +            assert iterator.hasNext() : "Expecting a single partition but got 
nothing";
 +            try (RowIterator partition = iterator.next())
 +            {
 +                assert !iterator.hasNext() : "Expecting a single partition 
but got more";
 +                return FilteredPartition.create(partition);
 +            }
 +        }
 +    }
 +
 +    public static UnfilteredRowIterator apply(Mutation mutation)
 +    {
 +        mutation.apply();
 +        assert mutation.getPartitionUpdates().size() == 1;
 +        return 
mutation.getPartitionUpdates().iterator().next().unfilteredIterator();
 +    }
 +
 +    public static Cell cell(ColumnFamilyStore cfs, Row row, String columnName)
 +    {
 +        ColumnDefinition def = 
cfs.metadata.getColumnDefinition(ByteBufferUtil.bytes(columnName));
 +        assert def != null;
 +        return row.getCell(def);
 +    }
 +
 +    public static Row row(Partition partition, Object... clustering)
 +    {
 +        return 
partition.getRow(partition.metadata().comparator.make(clustering));
 +    }
 +
 +    public static void assertCellValue(Object value, ColumnFamilyStore cfs, 
Row row, String columnName)
 +    {
 +        Cell cell = cell(cfs, row, columnName);
 +        assert cell != null : "Row " + row.toString(cfs.metadata) + " has no 
cell for " + columnName;
 +        assertEquals(value, cell.column().type.compose(cell.value()));
 +    }
 +
 +    public static void consume(UnfilteredRowIterator iter)
 +    {
 +        try (UnfilteredRowIterator iterator = iter)
          {
 -            return ByteBufferUtil.string(bb);
 +            while (iter.hasNext())
 +                iter.next();
          }
 -        catch (Exception e)
 +    }
 +
 +    public static int size(PartitionIterator iter)
 +    {
 +        int size = 0;
 +        while (iter.hasNext())
          {
 -            throw new RuntimeException(e);
 +            ++size;
 +            iter.next().close();
          }
 +        return size;
      }
  
 -    public static RangeTombstone tombstone(String start, String finish, long 
timestamp, int localtime)
 +    public static CBuilder getCBuilderForCFM(CFMetaData cfm)
      {
 -        Composite startName = 
CellNames.simpleDense(ByteBufferUtil.bytes(start));
 -        Composite endName = 
CellNames.simpleDense(ByteBufferUtil.bytes(finish));
 -        return new RangeTombstone(startName, endName, timestamp , localtime);
 +        List<ColumnDefinition> clusteringColumns = cfm.clusteringColumns();
 +        List<AbstractType<?>> types = new 
ArrayList<>(clusteringColumns.size());
 +        for (ColumnDefinition def : clusteringColumns)
 +            types.add(def.type);
 +        return CBuilder.create(new ClusteringComparator(types));
 +    }
 +
 +    public static boolean equal(UnfilteredRowIterator a, 
UnfilteredRowIterator b)
 +    {
 +        return Objects.equals(a.columns(), b.columns())
 +            && Objects.equals(a.metadata(), b.metadata())
 +            && Objects.equals(a.isReverseOrder(), b.isReverseOrder())
 +            && Objects.equals(a.partitionKey(), b.partitionKey())
 +            && Objects.equals(a.partitionLevelDeletion(), 
b.partitionLevelDeletion())
 +            && Objects.equals(a.staticRow(), b.staticRow())
 +            && Objects.equals(a.stats(), b.stats())
 +            && Iterators.elementsEqual(a, b);
 +    }
 +
 +    // moved & refactored from KeyspaceTest in < 3.0
 +    public static void assertColumns(Row row, String... expectedColumnNames)
 +    {
 +        Iterator<Cell> cells = row == null ? Iterators.<Cell>emptyIterator() 
: row.cells().iterator();
 +        String[] actual = Iterators.toArray(Iterators.transform(cells, new 
Function<Cell, String>()
 +        {
 +            public String apply(Cell cell)
 +            {
 +                return cell.column().name.toString();
 +            }
 +        }), String.class);
 +
 +        assert Arrays.equals(actual, expectedColumnNames)
 +        : String.format("Columns [%s])] is not expected [%s]",
 +                        ((row == null) ? "" : row.columns().toString()),
 +                        StringUtils.join(expectedColumnNames, ","));
 +    }
 +
 +    public static void assertColumn(CFMetaData cfm, Row row, String name, 
String value, long timestamp)
 +    {
 +        Cell cell = row.getCell(cfm.getColumnDefinition(new 
ColumnIdentifier(name, true)));
 +        assertColumn(cell, value, timestamp);
 +    }
 +
 +    public static void assertColumn(Cell cell, String value, long timestamp)
 +    {
 +        assertNotNull(cell);
 +        assertEquals(0, ByteBufferUtil.compareUnsigned(cell.value(), 
ByteBufferUtil.bytes(value)));
 +        assertEquals(timestamp, cell.timestamp());
 +    }
 +
 +    public static void assertClustering(CFMetaData cfm, Row row, Object... 
clusteringValue)
 +    {
 +        assertEquals(row.clustering().size(), clusteringValue.length);
 +        assertEquals(0, cfm.comparator.compare(row.clustering(), 
cfm.comparator.make(clusteringValue)));
 +    }
 +
-     public static void spinAssertEquals(Object expected, Supplier<Object> s, 
int timeoutInSeconds)
-     {
-         long now = System.currentTimeMillis();
-         while (System.currentTimeMillis() - now < now + (1000 * 
timeoutInSeconds))
-         {
-             if (s.get().equals(expected))
-                 break;
-             Thread.yield();
-         }
-         assertEquals(expected, s.get());
-     }
- 
 +    public static PartitionerSwitcher switchPartitioner(IPartitioner p)
 +    {
 +        return new PartitionerSwitcher(p);
 +    }
 +
 +    public static class PartitionerSwitcher implements AutoCloseable
 +    {
 +        final IPartitioner oldP;
 +        final IPartitioner newP;
 +
 +        public PartitionerSwitcher(IPartitioner partitioner)
 +        {
 +            newP = partitioner;
 +            oldP = StorageService.instance.setPartitionerUnsafe(partitioner);
 +        }
 +
 +        public void close()
 +        {
 +            IPartitioner p = 
StorageService.instance.setPartitionerUnsafe(oldP);
 +            assert p == newP;
 +        }
      }
  
+     public static void spinAssertEquals(Object expected, Supplier<Object> s, 
int timeoutInSeconds)
+     {
+         long now = System.currentTimeMillis();
+         while (System.currentTimeMillis() - now < now + (1000 * 
timeoutInSeconds))
+         {
+             if (s.get().equals(expected))
+                 break;
+             Thread.yield();
+         }
+         assertEquals(expected, s.get());
+     }
+ 
      public static void joinThread(Thread thread) throws InterruptedException
      {
          thread.join(10000);

Reply via email to