cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mish...@apache.org
Subject [6/6] git commit: Merge branch 'cassandra-2.1' into trunk
Date Fri, 15 Aug 2014 20:26:59 GMT
Merge branch 'cassandra-2.1' into trunk

Conflicts:
	test/unit/org/apache/cassandra/tools/SSTableImportTest.java


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

Branch: refs/heads/trunk
Commit: f0635da39ddfb68c856db58b698855b9f44e698e
Parents: 5233948 141b939
Author: Mikhail Stepura <mishail@apache.org>
Authored: Fri Aug 15 13:26:40 2014 -0700
Committer: Mikhail Stepura <mishail@apache.org>
Committed: Fri Aug 15 13:26:40 2014 -0700

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../apache/cassandra/tools/SSTableImport.java   | 12 +++-
 test/resources/CQLTable.json                    | 10 +++
 .../cassandra/tools/SSTableImportTest.java      | 72 ++++++++++++++++++--
 4 files changed, 87 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f0635da3/CHANGES.txt
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f0635da3/src/java/org/apache/cassandra/tools/SSTableImport.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f0635da3/test/unit/org/apache/cassandra/tools/SSTableImportTest.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/tools/SSTableImportTest.java
index 5c4318a,38e5914..01becfe
--- a/test/unit/org/apache/cassandra/tools/SSTableImportTest.java
+++ b/test/unit/org/apache/cassandra/tools/SSTableImportTest.java
@@@ -18,58 -18,39 +18,71 @@@
  */
  package org.apache.cassandra.tools;
  
 -import static org.hamcrest.CoreMatchers.is;
+ import static org.junit.Assert.assertEquals;
++import static org.hamcrest.CoreMatchers.is;
+ import static org.junit.Assert.assertThat;
+ import static org.junit.matchers.JUnitMatchers.hasItem;
+ 
+ import static org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile;
+ import static org.apache.cassandra.utils.ByteBufferUtil.hexToBytes;
+ 
  import java.io.File;
  import java.io.IOException;
  import java.net.URI;
  import java.net.URISyntaxException;
  
 +import org.junit.BeforeClass;
+ import org.hamcrest.Description;
+ import org.hamcrest.Matcher;
  import org.junit.Test;
+ import org.junit.internal.matchers.TypeSafeMatcher;
  
  import org.apache.cassandra.SchemaLoader;
  import org.apache.cassandra.Util;
++import org.apache.cassandra.db.*;
 +import org.apache.cassandra.config.CFMetaData;
 +import org.apache.cassandra.config.KSMetaData;
 +import org.apache.cassandra.db.ArrayBackedSortedColumns;
 +import org.apache.cassandra.db.BufferDeletedCell;
 +import org.apache.cassandra.db.Cell;
 +import org.apache.cassandra.db.ColumnFamily;
 +import org.apache.cassandra.db.CounterCell;
 +import org.apache.cassandra.db.DeletionInfo;
 +import org.apache.cassandra.db.ExpiringCell;
+ import org.apache.cassandra.cql3.QueryProcessor;
+ import org.apache.cassandra.cql3.UntypedResultSet;
+ import org.apache.cassandra.cql3.UntypedResultSet.Row;
 -import org.apache.cassandra.db.*;
  import org.apache.cassandra.db.columniterator.OnDiskAtomIterator;
  import org.apache.cassandra.db.filter.QueryFilter;
  import org.apache.cassandra.db.marshal.AsciiType;
  import org.apache.cassandra.db.marshal.BytesType;
 +import org.apache.cassandra.db.marshal.CounterColumnType;
 +import org.apache.cassandra.exceptions.ConfigurationException;
  import org.apache.cassandra.io.sstable.Descriptor;
  import org.apache.cassandra.io.sstable.SSTableReader;
 +import org.apache.cassandra.locator.SimpleStrategy;
 +import org.apache.thrift.TException;
  
- import static org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile;
- import static org.apache.cassandra.utils.ByteBufferUtil.hexToBytes;
- import static org.junit.Assert.assertEquals;
- 
 -public class SSTableImportTest extends SchemaLoader
 +public class SSTableImportTest
  {
 +    public static final String KEYSPACE1 = "SSTableImportTest";
 +    public static final String CF_STANDARD = "Standard1";
 +    public static final String CF_COUNTER = "Counter1";
++    public static final String CQL_TABLE = "table1";
 +
 +    @BeforeClass
 +    public static void defineSchema() throws ConfigurationException, IOException, TException
 +    {
 +        SchemaLoader.prepareServer();
 +        SchemaLoader.createKeyspace(KEYSPACE1,
 +                                    SimpleStrategy.class,
 +                                    KSMetaData.optsWithRF(1),
 +                                    SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD),
 +                                    CFMetaData.denseCFMetaData(KEYSPACE1, CF_COUNTER, BytesType.instance).defaultValidator(CounterColumnType.instance),
-                                     SchemaLoader.standardCFMD(KEYSPACE1, "AsciiKeys").keyValidator(AsciiType.instance));
++                                    SchemaLoader.standardCFMD(KEYSPACE1, "AsciiKeys").keyValidator(AsciiType.instance),
++                                    CFMetaData.compile("CREATE TABLE table1 (k int PRIMARY
KEY, v1 text, v2 int)", KEYSPACE1));
 +    }
 +
      @Test
      public void testImportSimpleCf() throws IOException, URISyntaxException
      {
@@@ -205,4 -186,55 +218,53 @@@
          OnDiskAtomIterator iter = qf.getSSTableColumnIterator(reader);
          assert iter.hasNext(); // "bytes" key exists
      }
+     
+     @Test
+     /* 
+      *  The schema is 
+      *      CREATE TABLE cql_keyspace.table1 (k int PRIMARY KEY, v1 text, v2 int)
+      * */
+     public void shouldImportCqlTable() throws IOException, URISyntaxException
+     {
 -        String cql_keyspace = "cql_keyspace";
 -        String cql_table = "table1";
+         String jsonUrl = resourcePath("CQLTable.json");
 -        File tempSS = tempSSTableFile(cql_keyspace, cql_table);
 -        new SSTableImport(true).importJson(jsonUrl, cql_keyspace, cql_table, tempSS.getPath());
++        File tempSS = tempSSTableFile(KEYSPACE1, CQL_TABLE);
++        new SSTableImport(true).importJson(jsonUrl, KEYSPACE1, CQL_TABLE, tempSS.getPath());
+         SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath()));
 -        Keyspace.open(cql_keyspace).getColumnFamilyStore(cql_table).addSSTable(reader);
++        Keyspace.open(KEYSPACE1).getColumnFamilyStore(CQL_TABLE).addSSTable(reader);
+         
 -        UntypedResultSet result = QueryProcessor.executeOnceInternal(String.format("SELECT
* FROM %s.%s", cql_keyspace, cql_table));
++        UntypedResultSet result = QueryProcessor.executeOnceInternal(String.format("SELECT
* FROM \"%s\".%s", KEYSPACE1, CQL_TABLE));
+         assertThat(result.size(), is(2));
+         assertThat(result, hasItem(withElements(1, "NY", 1980)));
+         assertThat(result, hasItem(withElements(2, "CA", 2014)));
+     }
+ 
+     @Test(expected=AssertionError.class)
+     public void shouldRejectEmptyCellNamesForNonCqlTables() throws IOException, URISyntaxException
+     {
+         String jsonUrl = resourcePath("CQLTable.json");
+         File tempSS = tempSSTableFile("Keyspace1", "Counter1");
+         new SSTableImport(true).importJson(jsonUrl, "Keyspace1", "Counter1", tempSS.getPath());
+     }
+     
+     private static Matcher<UntypedResultSet.Row> withElements(final int key, final
String v1, final int v2) {
+         return new TypeSafeMatcher<UntypedResultSet.Row>()
+         {
+             @Override
+             public boolean matchesSafely(Row input)
+             {
+                 if (!input.has("k") || !input.has("v1") || !input.has("v2"))
+                     return false;
+                 return input.getInt("k") == key
+                         && input.getString("v1").equals(v1)
+                         && input.getInt("v2") == v2;
+             }
+ 
+             @Override
+             public void describeTo(Description description)
+             {
+                 description.appendText(String.format("a row containing: %s, %s, %s", key,
v1, v2));
+             }
+         };
+         
+     }
  }


Mime
View raw message