Repository: cassandra Updated Branches: refs/heads/trunk 51016876a -> d2a3827a6
http://git-wip-us.apache.org/repos/asf/cassandra/blob/d2a3827a/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java b/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java index 47136a0..52b2236 100644 --- a/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java +++ b/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java @@ -35,17 +35,23 @@ import org.slf4j.LoggerFactory; import org.apache.cassandra.OrderedJUnit4ClassRunner; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; +import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.config.KSMetaData; import org.apache.cassandra.db.*; import org.apache.cassandra.db.columniterator.IdentityQueryFilter; import org.apache.cassandra.db.context.CounterContext; import org.apache.cassandra.db.filter.IDiskAtomFilter; import org.apache.cassandra.db.filter.QueryFilter; +import org.apache.cassandra.db.marshal.BytesType; +import org.apache.cassandra.db.marshal.CounterColumnType; +import org.apache.cassandra.db.marshal.IntegerType; import org.apache.cassandra.dht.IPartitioner; import org.apache.cassandra.dht.Range; import org.apache.cassandra.dht.Token; import org.apache.cassandra.io.sstable.SSTableReader; import org.apache.cassandra.io.sstable.SSTableUtils; +import org.apache.cassandra.locator.SimpleStrategy; import org.apache.cassandra.service.StorageService; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.CounterId; @@ -57,16 +63,42 @@ import static org.apache.cassandra.Util.cellname; import static org.apache.cassandra.Util.column; @RunWith(OrderedJUnit4ClassRunner.class) -public class StreamingTransferTest extends SchemaLoader +public class StreamingTransferTest { private static final Logger logger = LoggerFactory.getLogger(StreamingTransferTest.class); public static final InetAddress LOCAL = FBUtilities.getBroadcastAddress(); + public static final String KEYSPACE1 = "StreamingTransferTest1"; + public static final String CF_STANDARD = "Standard1"; + public static final String CF_COUNTER = "Counter1"; + public static final String CF_STANDARDINT = "StandardInteger1"; + public static final String CF_INDEX = "Indexed1"; + public static final String KEYSPACE_CACHEKEY = "KeyStreamingTransferTestSpace"; + public static final String CF_STANDARD2 = "Standard2"; + public static final String CF_STANDARD3 = "Standard3"; + public static final String KEYSPACE2 = "StreamingTransferTest2"; @BeforeClass - public static void setup() throws Exception + public static void defineSchema() throws Exception { + SchemaLoader.prepareServer(); StorageService.instance.initServer(); + SchemaLoader.createKeyspace(KEYSPACE1, + SimpleStrategy.class, + KSMetaData.optsWithRF(1), + SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD), + CFMetaData.denseCFMetaData(KEYSPACE1, CF_COUNTER, BytesType.instance).defaultValidator(CounterColumnType.instance), + CFMetaData.denseCFMetaData(KEYSPACE1, CF_STANDARDINT, IntegerType.instance), + SchemaLoader.indexCFMD(KEYSPACE1, CF_INDEX, true)); + SchemaLoader.createKeyspace(KEYSPACE2, + SimpleStrategy.class, + KSMetaData.optsWithRF(1)); + SchemaLoader.createKeyspace(KEYSPACE_CACHEKEY, + SimpleStrategy.class, + KSMetaData.optsWithRF(1), + SchemaLoader.standardCFMD(KEYSPACE_CACHEKEY, CF_STANDARD), + SchemaLoader.standardCFMD(KEYSPACE_CACHEKEY, CF_STANDARD2), + SchemaLoader.standardCFMD(KEYSPACE_CACHEKEY, CF_STANDARD3)); } /** @@ -105,7 +137,7 @@ public class StreamingTransferTest extends SchemaLoader ranges.add(new Range<>(p.getToken(ByteBufferUtil.bytes("key2")), p.getMinimumToken())); StreamResultFuture futureResult = new StreamPlan("StreamingTransferTest") - .requestRanges(LOCAL, "Keyspace2", ranges) + .requestRanges(LOCAL, KEYSPACE2, ranges) .execute(); UUID planId = futureResult.planId; @@ -219,7 +251,7 @@ public class StreamingTransferTest extends SchemaLoader private void doTransferTable(boolean transferSSTables) throws Exception { - final Keyspace keyspace = Keyspace.open("Keyspace1"); + final Keyspace keyspace = Keyspace.open(KEYSPACE1); final ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Indexed1"); List<String> keys = createAndTransfer(cfs, new Mutator() @@ -230,7 +262,7 @@ public class StreamingTransferTest extends SchemaLoader ColumnFamily cf = ArrayBackedSortedColumns.factory.create(keyspace.getName(), cfs.name); cf.addColumn(column(col, "v", timestamp)); cf.addColumn(new BufferCell(cellname("birthdate"), ByteBufferUtil.bytes(val), timestamp)); - Mutation rm = new Mutation("Keyspace1", ByteBufferUtil.bytes(key), cf); + Mutation rm = new Mutation(KEYSPACE1, ByteBufferUtil.bytes(key), cf); logger.debug("Applying row to transfer {}", rm); rm.apply(); } @@ -258,7 +290,7 @@ public class StreamingTransferTest extends SchemaLoader @Test public void testTransferRangeTombstones() throws Exception { - String ks = "Keyspace1"; + String ks = KEYSPACE1; String cfname = "StandardInteger1"; Keyspace keyspace = Keyspace.open(ks); ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfname); @@ -301,7 +333,7 @@ public class StreamingTransferTest extends SchemaLoader @Test public void testTransferTableCounter() throws Exception { - final Keyspace keyspace = Keyspace.open("Keyspace1"); + final Keyspace keyspace = Keyspace.open(KEYSPACE1); final ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Counter1"); final CounterContext cc = new CounterContext(); @@ -358,7 +390,7 @@ public class StreamingTransferTest extends SchemaLoader content.add("test"); content.add("test2"); content.add("test3"); - SSTableReader sstable = SSTableUtils.prepare().write(content); + SSTableReader sstable = new SSTableUtils(KEYSPACE1, CF_STANDARD).prepare().write(content); String keyspaceName = sstable.getKeyspaceName(); String cfname = sstable.getColumnFamilyName(); @@ -397,7 +429,7 @@ public class StreamingTransferTest extends SchemaLoader @Test public void testTransferOfMultipleColumnFamilies() throws Exception { - String keyspace = "KeyCacheSpace"; + String keyspace = KEYSPACE_CACHEKEY; IPartitioner p = StorageService.getPartitioner(); String[] columnFamilies = new String[] { "Standard1", "Standard2", "Standard3" }; List<SSTableReader> ssTableReaders = new ArrayList<>(); @@ -445,7 +477,7 @@ public class StreamingTransferTest extends SchemaLoader @Test public void testRandomSSTableTransfer() throws Exception { - final Keyspace keyspace = Keyspace.open("Keyspace1"); + final Keyspace keyspace = Keyspace.open(KEYSPACE1); final ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Standard1"); Mutator mutator = new Mutator() { @@ -454,7 +486,7 @@ public class StreamingTransferTest extends SchemaLoader ColumnFamily cf = ArrayBackedSortedColumns.factory.create(keyspace.getName(), cfs.name); cf.addColumn(column(colName, "value", timestamp)); cf.addColumn(new BufferCell(cellname("birthdate"), ByteBufferUtil.bytes(new Date(timestamp).toString()), timestamp)); - Mutation rm = new Mutation("Keyspace1", ByteBufferUtil.bytes(key), cf); + Mutation rm = new Mutation(KEYSPACE1, ByteBufferUtil.bytes(key), cf); logger.debug("Applying row to transfer {}", rm); rm.apply(); } http://git-wip-us.apache.org/repos/asf/cassandra/blob/d2a3827a/test/unit/org/apache/cassandra/thrift/MultiSliceTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/thrift/MultiSliceTest.java b/test/unit/org/apache/cassandra/thrift/MultiSliceTest.java index 50e409e..9716876 100644 --- a/test/unit/org/apache/cassandra/thrift/MultiSliceTest.java +++ b/test/unit/org/apache/cassandra/thrift/MultiSliceTest.java @@ -28,25 +28,33 @@ import java.util.List; import junit.framework.Assert; import org.apache.cassandra.SchemaLoader; -import org.apache.cassandra.config.Schema; +import org.apache.cassandra.config.KSMetaData; +import org.apache.cassandra.exceptions.ConfigurationException; +import org.apache.cassandra.locator.SimpleStrategy; import org.apache.cassandra.service.EmbeddedCassandraService; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.thrift.TException; import org.junit.BeforeClass; import org.junit.Test; -public class MultiSliceTest extends SchemaLoader +public class MultiSliceTest { private static CassandraServer server; - + public static final String KEYSPACE1 = "MultiSliceTest"; + public static final String CF_STANDARD = "Standard1"; + @BeforeClass - public static void setup() throws IOException, TException + public static void defineSchema() throws ConfigurationException, IOException, TException { - Schema.instance.clear(); // Schema are now written on disk and will be reloaded + SchemaLoader.prepareServer(); new EmbeddedCassandraService().start(); - ThriftSessionManager.instance.setCurrentSocket(new InetSocketAddress(9160)); + ThriftSessionManager.instance.setCurrentSocket(new InetSocketAddress(9160)); + SchemaLoader.createKeyspace(KEYSPACE1, + SimpleStrategy.class, + KSMetaData.optsWithRF(1), + SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD)); server = new CassandraServer(); - server.set_keyspace("Keyspace1"); + server.set_keyspace(KEYSPACE1); } private static MultiSliceRequest makeMultiSliceRequest(ByteBuffer key) http://git-wip-us.apache.org/repos/asf/cassandra/blob/d2a3827a/test/unit/org/apache/cassandra/thrift/ThriftValidationTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/thrift/ThriftValidationTest.java b/test/unit/org/apache/cassandra/thrift/ThriftValidationTest.java index df0f98c..e81dd3d 100644 --- a/test/unit/org/apache/cassandra/thrift/ThriftValidationTest.java +++ b/test/unit/org/apache/cassandra/thrift/ThriftValidationTest.java @@ -20,40 +20,62 @@ package org.apache.cassandra.thrift; * */ -import org.apache.cassandra.db.marshal.LongType; -import org.apache.cassandra.exceptions.*; +import org.junit.BeforeClass; import org.junit.Test; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.config.*; -import org.apache.cassandra.db.marshal.AsciiType; +import org.apache.cassandra.db.marshal.*; +import org.apache.cassandra.exceptions.*; import org.apache.cassandra.locator.LocalStrategy; import org.apache.cassandra.locator.NetworkTopologyStrategy; +import org.apache.cassandra.locator.SimpleStrategy; import org.apache.cassandra.utils.ByteBufferUtil; +import org.apache.thrift.TException; +import java.io.IOException; import java.util.Arrays; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertEquals; -public class ThriftValidationTest extends SchemaLoader +public class ThriftValidationTest { + public static final String KEYSPACE1 = "MultiSliceTest"; + public static final String CF_STANDARD = "Standard1"; + public static final String CF_COUNTER = "Counter1"; + public static final String CF_UUID = "UUIDKeys"; + public static final String CF_STANDARDLONG3 = "StandardLong3"; + + @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, CF_UUID).keyValidator(UUIDType.instance), + CFMetaData.denseCFMetaData(KEYSPACE1, CF_STANDARDLONG3, IntegerType.instance)); + } + @Test(expected=org.apache.cassandra.exceptions.InvalidRequestException.class) public void testValidateCommutativeWithStandard() throws org.apache.cassandra.exceptions.InvalidRequestException { - ThriftValidation.validateColumnFamily("Keyspace1", "Standard1", true); + ThriftValidation.validateColumnFamily(KEYSPACE1, "Standard1", true); } @Test public void testValidateCommutativeWithCounter() throws org.apache.cassandra.exceptions.InvalidRequestException { - ThriftValidation.validateColumnFamily("Keyspace1", "Counter1", true); + ThriftValidation.validateColumnFamily(KEYSPACE1, "Counter1", true); } @Test public void testColumnNameEqualToKeyAlias() throws org.apache.cassandra.exceptions.InvalidRequestException { - CFMetaData metaData = Schema.instance.getCFMetaData("Keyspace1", "Standard1"); + CFMetaData metaData = Schema.instance.getCFMetaData(KEYSPACE1, "Standard1"); CFMetaData newMetadata = metaData.copy(); boolean gotException = false; @@ -98,7 +120,7 @@ public class ThriftValidationTest extends SchemaLoader @Test public void testColumnNameEqualToDefaultKeyAlias() throws org.apache.cassandra.exceptions.InvalidRequestException { - CFMetaData metaData = Schema.instance.getCFMetaData("Keyspace1", "UUIDKeys"); + CFMetaData metaData = Schema.instance.getCFMetaData(KEYSPACE1, "UUIDKeys"); ColumnDefinition definition = metaData.getColumnDefinition(ByteBufferUtil.bytes(CFMetaData.DEFAULT_KEY_ALIAS)); assertNotNull(definition); assertEquals(ColumnDefinition.Kind.PARTITION_KEY, definition.kind); @@ -116,7 +138,7 @@ public class ThriftValidationTest extends SchemaLoader @Test public void testColumnNameEqualToDefaultColumnAlias() throws org.apache.cassandra.exceptions.InvalidRequestException { - CFMetaData metaData = Schema.instance.getCFMetaData("Keyspace1", "StandardLong3"); + CFMetaData metaData = Schema.instance.getCFMetaData(KEYSPACE1, "StandardLong3"); ColumnDefinition definition = metaData.getColumnDefinition(ByteBufferUtil.bytes(CFMetaData.DEFAULT_COLUMN_ALIAS + 1)); assertNotNull(definition); http://git-wip-us.apache.org/repos/asf/cassandra/blob/d2a3827a/test/unit/org/apache/cassandra/tools/SSTableExportTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/tools/SSTableExportTest.java b/test/unit/org/apache/cassandra/tools/SSTableExportTest.java index d9133f6..dbc6703 100644 --- a/test/unit/org/apache/cassandra/tools/SSTableExportTest.java +++ b/test/unit/org/apache/cassandra/tools/SSTableExportTest.java @@ -34,23 +34,50 @@ import java.io.PrintStream; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; import org.apache.cassandra.config.CFMetaData; +import org.apache.cassandra.config.KSMetaData; import org.apache.cassandra.db.*; import org.apache.cassandra.db.filter.QueryFilter; +import org.apache.cassandra.db.marshal.BytesType; +import org.apache.cassandra.db.marshal.CounterColumnType; import org.apache.cassandra.db.marshal.UTF8Type; +import org.apache.cassandra.db.marshal.UUIDType; +import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.io.sstable.Descriptor; import org.apache.cassandra.io.sstable.SSTableReader; import org.apache.cassandra.io.sstable.SSTableWriter; +import org.apache.cassandra.locator.SimpleStrategy; import org.apache.cassandra.service.ActiveRepairService; import org.apache.cassandra.utils.ByteBufferUtil; import org.apache.cassandra.utils.UUIDGen; +import org.apache.thrift.TException; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.JSONValue; import org.json.simple.parser.ParseException; +import org.junit.BeforeClass; import org.junit.Test; -public class SSTableExportTest extends SchemaLoader +public class SSTableExportTest { + public static final String KEYSPACE1 = "SSTableExportTest"; + public static final String CF_STANDARD = "Standard1"; + public static final String CF_COUNTER = "Counter1"; + public static final String CF_UUID = "UUIDKeys"; + public static final String CF_VALSWITHQUOTES = "ValuesWithQuotes"; + + @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, CF_UUID).keyValidator(UUIDType.instance), + CFMetaData.denseCFMetaData(KEYSPACE1, CF_VALSWITHQUOTES, BytesType.instance).defaultValidator(UTF8Type.instance)); + } + public String asHex(String str) { return bytesToHex(ByteBufferUtil.bytes(str)); @@ -59,8 +86,8 @@ public class SSTableExportTest extends SchemaLoader @Test public void testEnumeratekeys() throws IOException { - File tempSS = tempSSTableFile("Keyspace1", "Standard1"); - ColumnFamily cfamily = ArrayBackedSortedColumns.factory.create("Keyspace1", "Standard1"); + File tempSS = tempSSTableFile(KEYSPACE1, "Standard1"); + ColumnFamily cfamily = ArrayBackedSortedColumns.factory.create(KEYSPACE1, "Standard1"); SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2, ActiveRepairService.UNREPAIRED_SSTABLE); // Add rowA @@ -94,8 +121,8 @@ public class SSTableExportTest extends SchemaLoader @Test public void testExportSimpleCf() throws IOException, ParseException { - File tempSS = tempSSTableFile("Keyspace1", "Standard1"); - ColumnFamily cfamily = ArrayBackedSortedColumns.factory.create("Keyspace1", "Standard1"); + File tempSS = tempSSTableFile(KEYSPACE1, "Standard1"); + ColumnFamily cfamily = ArrayBackedSortedColumns.factory.create(KEYSPACE1, "Standard1"); SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2, ActiveRepairService.UNREPAIRED_SSTABLE); int nowInSec = (int)(System.currentTimeMillis() / 1000) + 42; //live for 42 seconds @@ -149,9 +176,9 @@ public class SSTableExportTest extends SchemaLoader @Test public void testRoundTripStandardCf() throws IOException { - ColumnFamilyStore cfs = Keyspace.open("Keyspace1").getColumnFamilyStore("Standard1"); - File tempSS = tempSSTableFile("Keyspace1", "Standard1"); - ColumnFamily cfamily = ArrayBackedSortedColumns.factory.create("Keyspace1", "Standard1"); + ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore("Standard1"); + File tempSS = tempSSTableFile(KEYSPACE1, "Standard1"); + ColumnFamily cfamily = ArrayBackedSortedColumns.factory.create(KEYSPACE1, "Standard1"); SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2, ActiveRepairService.UNREPAIRED_SSTABLE); // Add rowA @@ -171,8 +198,8 @@ public class SSTableExportTest extends SchemaLoader SSTableExport.export(reader, new PrintStream(tempJson.getPath()), new String[]{asHex("rowExclude")}); // Import JSON to another SSTable file - File tempSS2 = tempSSTableFile("Keyspace1", "Standard1"); - new SSTableImport().importJson(tempJson.getPath(), "Keyspace1", "Standard1", tempSS2.getPath()); + File tempSS2 = tempSSTableFile(KEYSPACE1, "Standard1"); + new SSTableImport().importJson(tempJson.getPath(), KEYSPACE1, "Standard1", tempSS2.getPath()); reader = SSTableReader.open(Descriptor.fromFilename(tempSS2.getPath())); QueryFilter qf = Util.namesQueryFilter(cfs, Util.dk("rowA"), "name"); @@ -189,8 +216,8 @@ public class SSTableExportTest extends SchemaLoader @Test public void testExportCounterCf() throws IOException, ParseException { - File tempSS = tempSSTableFile("Keyspace1", "Counter1"); - ColumnFamily cfamily = ArrayBackedSortedColumns.factory.create("Keyspace1", "Counter1"); + File tempSS = tempSSTableFile(KEYSPACE1, "Counter1"); + ColumnFamily cfamily = ArrayBackedSortedColumns.factory.create(KEYSPACE1, "Counter1"); SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2, ActiveRepairService.UNREPAIRED_SSTABLE); // Add rowA @@ -220,8 +247,8 @@ public class SSTableExportTest extends SchemaLoader @Test public void testEscapingDoubleQuotes() throws IOException, ParseException { - File tempSS = tempSSTableFile("Keyspace1", "ValuesWithQuotes"); - ColumnFamily cfamily = ArrayBackedSortedColumns.factory.create("Keyspace1", "ValuesWithQuotes"); + File tempSS = tempSSTableFile(KEYSPACE1, "ValuesWithQuotes"); + ColumnFamily cfamily = ArrayBackedSortedColumns.factory.create(KEYSPACE1, "ValuesWithQuotes"); SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2, ActiveRepairService.UNREPAIRED_SSTABLE); // Add rowA @@ -251,8 +278,8 @@ public class SSTableExportTest extends SchemaLoader @Test public void testExportColumnsWithMetadata() throws IOException, ParseException { - File tempSS = tempSSTableFile("Keyspace1", "Standard1"); - ColumnFamily cfamily = ArrayBackedSortedColumns.factory.create("Keyspace1", "Standard1"); + File tempSS = tempSSTableFile(KEYSPACE1, "Standard1"); + ColumnFamily cfamily = ArrayBackedSortedColumns.factory.create(KEYSPACE1, "Standard1"); SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2, ActiveRepairService.UNREPAIRED_SSTABLE); // Add rowA @@ -312,8 +339,8 @@ public class SSTableExportTest extends SchemaLoader @Test public void testColumnNameEqualToDefaultKeyAlias() throws IOException, ParseException { - File tempSS = tempSSTableFile("Keyspace1", "UUIDKeys"); - ColumnFamily cfamily = ArrayBackedSortedColumns.factory.create("Keyspace1", "UUIDKeys"); + File tempSS = tempSSTableFile(KEYSPACE1, "UUIDKeys"); + ColumnFamily cfamily = ArrayBackedSortedColumns.factory.create(KEYSPACE1, "UUIDKeys"); SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2, ActiveRepairService.UNREPAIRED_SSTABLE); // Add a row http://git-wip-us.apache.org/repos/asf/cassandra/blob/d2a3827a/test/unit/org/apache/cassandra/tools/SSTableImportTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/tools/SSTableImportTest.java b/test/unit/org/apache/cassandra/tools/SSTableImportTest.java index 2fdeaf4..dba8408 100644 --- a/test/unit/org/apache/cassandra/tools/SSTableImportTest.java +++ b/test/unit/org/apache/cassandra/tools/SSTableImportTest.java @@ -27,26 +27,48 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import org.junit.BeforeClass; import org.junit.Test; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; +import org.apache.cassandra.config.CFMetaData; +import org.apache.cassandra.config.KSMetaData; 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.BytesType; +import org.apache.cassandra.db.marshal.CounterColumnType; +import org.apache.cassandra.exceptions.ConfigurationException; +import org.apache.cassandra.locator.SimpleStrategy; import org.apache.cassandra.io.sstable.Descriptor; import org.apache.cassandra.io.sstable.SSTableReader; -import org.apache.cassandra.utils.ByteBufferUtil; +import org.apache.thrift.TException; -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"; + + @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)); + } + @Test public void testImportSimpleCf() throws IOException, URISyntaxException { // Import JSON to temp SSTable file String jsonUrl = resourcePath("SimpleCF.json"); - File tempSS = tempSSTableFile("Keyspace1", "Standard1"); - new SSTableImport(true).importJson(jsonUrl, "Keyspace1", "Standard1", tempSS.getPath()); + File tempSS = tempSSTableFile(KEYSPACE1, "Standard1"); + new SSTableImport(true).importJson(jsonUrl, KEYSPACE1, "Standard1", tempSS.getPath()); // Verify results SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath())); @@ -78,9 +100,9 @@ public class SSTableImportTest extends SchemaLoader public void testImportUnsortedMode() throws IOException, URISyntaxException { String jsonUrl = resourcePath("UnsortedCF.json"); - File tempSS = tempSSTableFile("Keyspace1", "Standard1"); + File tempSS = tempSSTableFile(KEYSPACE1, "Standard1"); - new SSTableImport().importJson(jsonUrl, "Keyspace1", "Standard1", tempSS.getPath()); + new SSTableImport().importJson(jsonUrl, KEYSPACE1, "Standard1", tempSS.getPath()); SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath())); QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), "Standard1", System.currentTimeMillis()); @@ -101,8 +123,8 @@ public class SSTableImportTest extends SchemaLoader { // Import JSON to temp SSTable file String jsonUrl = resourcePath("SimpleCFWithDeletionInfo.json"); - File tempSS = tempSSTableFile("Keyspace1", "Standard1"); - new SSTableImport(true).importJson(jsonUrl, "Keyspace1", "Standard1", tempSS.getPath()); + File tempSS = tempSSTableFile(KEYSPACE1, "Standard1"); + new SSTableImport(true).importJson(jsonUrl, KEYSPACE1, "Standard1", tempSS.getPath()); // Verify results SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath())); @@ -125,8 +147,8 @@ public class SSTableImportTest extends SchemaLoader { // Import JSON to temp SSTable file String jsonUrl = resourcePath("CounterCF.json"); - File tempSS = tempSSTableFile("Keyspace1", "Counter1"); - new SSTableImport(true).importJson(jsonUrl, "Keyspace1", "Counter1", tempSS.getPath()); + File tempSS = tempSSTableFile(KEYSPACE1, "Counter1"); + new SSTableImport(true).importJson(jsonUrl, KEYSPACE1, "Counter1", tempSS.getPath()); // Verify results SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath())); http://git-wip-us.apache.org/repos/asf/cassandra/blob/d2a3827a/test/unit/org/apache/cassandra/triggers/TriggersSchemaTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/triggers/TriggersSchemaTest.java b/test/unit/org/apache/cassandra/triggers/TriggersSchemaTest.java index c6a1ac5..577e7d3 100644 --- a/test/unit/org/apache/cassandra/triggers/TriggersSchemaTest.java +++ b/test/unit/org/apache/cassandra/triggers/TriggersSchemaTest.java @@ -19,6 +19,7 @@ package org.apache.cassandra.triggers; import java.util.Collections; +import org.junit.BeforeClass; import org.junit.Test; import org.apache.cassandra.SchemaLoader; @@ -26,6 +27,7 @@ import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.KSMetaData; import org.apache.cassandra.config.Schema; import org.apache.cassandra.config.TriggerDefinition; +import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.locator.SimpleStrategy; import org.apache.cassandra.service.MigrationManager; @@ -33,13 +35,19 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -public class TriggersSchemaTest extends SchemaLoader +public class TriggersSchemaTest { String ksName = "ks" + System.nanoTime(); String cfName = "cf" + System.nanoTime(); String triggerName = "trigger_" + System.nanoTime(); String triggerClass = "org.apache.cassandra.triggers.NoSuchTrigger.class"; + @BeforeClass + public static void beforeTest() throws ConfigurationException + { + SchemaLoader.loadSchema(); + } + @Test public void newKsContainsCfWithTrigger() throws Exception { http://git-wip-us.apache.org/repos/asf/cassandra/blob/d2a3827a/test/unit/org/apache/cassandra/triggers/TriggersTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/triggers/TriggersTest.java b/test/unit/org/apache/cassandra/triggers/TriggersTest.java index 74fde69..41d4bb8 100644 --- a/test/unit/org/apache/cassandra/triggers/TriggersTest.java +++ b/test/unit/org/apache/cassandra/triggers/TriggersTest.java @@ -24,6 +24,7 @@ import java.util.Collections; import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.apache.cassandra.SchemaLoader; @@ -35,6 +36,7 @@ import org.apache.cassandra.db.BufferCell; import org.apache.cassandra.db.ColumnFamily; import org.apache.cassandra.db.ConsistencyLevel; import org.apache.cassandra.db.Mutation; +import org.apache.cassandra.exceptions.ConfigurationException; import org.apache.cassandra.exceptions.RequestExecutionException; import org.apache.cassandra.service.StorageService; import org.apache.cassandra.thrift.*; @@ -46,7 +48,7 @@ import static org.junit.Assert.assertTrue; import static org.apache.cassandra.utils.ByteBufferUtil.bytes; import static org.apache.cassandra.utils.ByteBufferUtil.toInt; -public class TriggersTest extends SchemaLoader +public class TriggersTest { private static boolean triggerCreated = false; private static ThriftServer thriftServer; @@ -55,6 +57,12 @@ public class TriggersTest extends SchemaLoader private static String cfName = "test_table"; private static String otherCf = "other_table"; + @BeforeClass + public static void beforeTest() throws ConfigurationException + { + SchemaLoader.loadSchema(); + } + @Before public void setup() throws Exception { http://git-wip-us.apache.org/repos/asf/cassandra/blob/d2a3827a/test/unit/org/apache/cassandra/utils/EncodedStreamsTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/utils/EncodedStreamsTest.java b/test/unit/org/apache/cassandra/utils/EncodedStreamsTest.java index 2a67d42..957979f 100644 --- a/test/unit/org/apache/cassandra/utils/EncodedStreamsTest.java +++ b/test/unit/org/apache/cassandra/utils/EncodedStreamsTest.java @@ -26,25 +26,42 @@ import java.io.DataOutputStream; import java.io.IOException; import org.apache.cassandra.SchemaLoader; +import org.apache.cassandra.config.CFMetaData; +import org.apache.cassandra.config.KSMetaData; import org.apache.cassandra.db.ArrayBackedSortedColumns; import org.apache.cassandra.db.ColumnFamily; import org.apache.cassandra.db.TypeSizes; +import org.apache.cassandra.db.marshal.BytesType; +import org.apache.cassandra.db.marshal.CounterColumnType; +import org.apache.cassandra.exceptions.ConfigurationException; +import org.apache.cassandra.locator.SimpleStrategy; import org.apache.cassandra.net.MessagingService; import org.apache.cassandra.utils.vint.EncodedDataInputStream; import org.apache.cassandra.utils.vint.EncodedDataOutputStream; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; -public class EncodedStreamsTest extends SchemaLoader +public class EncodedStreamsTest { - private String keyspaceName = "Keyspace1"; - private String standardCFName = "Standard1"; - private String counterCFName = "Counter1"; - private String superCFName = "Super1"; - + private static final String KEYSPACE1 = "Keyspace1"; + private static final String CF_STANDARD = "Standard1"; + private static final String CF_COUNTER = "Counter1"; private int version = MessagingService.current_version; + @BeforeClass + public static void defineSchema() throws ConfigurationException + { + 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)); + } + @Test public void testStreams() throws IOException { @@ -97,7 +114,7 @@ public class EncodedStreamsTest extends SchemaLoader private ColumnFamily createCF() { - ColumnFamily cf = ArrayBackedSortedColumns.factory.create(keyspaceName, standardCFName); + ColumnFamily cf = ArrayBackedSortedColumns.factory.create(KEYSPACE1, CF_STANDARD); cf.addColumn(column("vijay", "try", 1)); cf.addColumn(column("to", "be_nice", 1)); return cf; @@ -105,7 +122,7 @@ public class EncodedStreamsTest extends SchemaLoader private ColumnFamily createCounterCF() { - ColumnFamily cf = ArrayBackedSortedColumns.factory.create(keyspaceName, counterCFName); + ColumnFamily cf = ArrayBackedSortedColumns.factory.create(KEYSPACE1, CF_COUNTER); cf.addCounter(cellname("vijay"), 1); cf.addCounter(cellname("wants"), 1000000); return cf;
