http://git-wip-us.apache.org/repos/asf/cassandra/blob/37b07935/test/unit/org/apache/cassandra/config/CFMetaDataTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/config/CFMetaDataTest.java b/test/unit/org/apache/cassandra/config/CFMetaDataTest.java index a43da27..1a67c04 100644 --- a/test/unit/org/apache/cassandra/config/CFMetaDataTest.java +++ b/test/unit/org/apache/cassandra/config/CFMetaDataTest.java @@ -21,7 +21,6 @@ package org.apache.cassandra.config; import java.util.ArrayList; import java.util.List; -import org.apache.avro.util.Utf8; import org.apache.cassandra.db.marshal.AsciiType; import org.apache.cassandra.db.marshal.UTF8Type; import org.apache.cassandra.thrift.CfDef; @@ -64,28 +63,28 @@ public class CFMetaDataTest CFMetaData cfMetaData = CFMetaData.fromThrift(cfDef); // make a correct Avro object - org.apache.cassandra.db.migration.avro.CfDef avroCfDef = new org.apache.cassandra.db.migration.avro.CfDef(); - avroCfDef.keyspace = new Utf8(KEYSPACE); - avroCfDef.name = new Utf8(COLUMN_FAMILY); - avroCfDef.default_validation_class = new Utf8(cfDef.default_validation_class); - avroCfDef.comment = new Utf8(cfDef.comment); - avroCfDef.column_metadata = new ArrayList<org.apache.cassandra.db.migration.avro.ColumnDef>(); + CfDef thriftCfDef = new CfDef(); + thriftCfDef.keyspace = KEYSPACE; + thriftCfDef.name = COLUMN_FAMILY; + thriftCfDef.default_validation_class = cfDef.default_validation_class; + thriftCfDef.comment = cfDef.comment; + thriftCfDef.column_metadata = new ArrayList<ColumnDef>(); for (ColumnDef columnDef : columnDefs) { - org.apache.cassandra.db.migration.avro.ColumnDef c = new org.apache.cassandra.db.migration.avro.ColumnDef(); + ColumnDef c = new ColumnDef(); c.name = ByteBufferUtil.clone(columnDef.name); - c.validation_class = new Utf8(columnDef.getValidation_class()); - c.index_name = new Utf8(columnDef.getIndex_name()); - c.index_type = org.apache.cassandra.db.migration.avro.IndexType.KEYS; - avroCfDef.column_metadata.add(c); + c.validation_class = columnDef.getValidation_class(); + c.index_name = columnDef.getIndex_name(); + c.index_type = IndexType.KEYS; + thriftCfDef.column_metadata.add(c); } - org.apache.cassandra.db.migration.avro.CfDef converted = cfMetaData.toAvro(); + CfDef converted = cfMetaData.toThrift(); - assertEquals(avroCfDef.keyspace, converted.keyspace); - assertEquals(avroCfDef.name, converted.name); - assertEquals(avroCfDef.default_validation_class, converted.default_validation_class); - assertEquals(avroCfDef.comment, converted.comment); - assertEquals(avroCfDef.column_metadata, converted.column_metadata); + assertEquals(thriftCfDef.keyspace, converted.keyspace); + assertEquals(thriftCfDef.name, converted.name); + assertEquals(thriftCfDef.default_validation_class, converted.default_validation_class); + assertEquals(thriftCfDef.comment, converted.comment); + assertEquals(thriftCfDef.column_metadata, converted.column_metadata); } }
http://git-wip-us.apache.org/repos/asf/cassandra/blob/37b07935/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java b/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java index 8302e7e..253f061 100644 --- a/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java +++ b/test/unit/org/apache/cassandra/config/ColumnDefinitionTest.java @@ -51,7 +51,7 @@ public class ColumnDefinitionTest protected void testSerializeDeserialize(ColumnDefinition cd) throws Exception { - ColumnDefinition newCd = ColumnDefinition.fromAvro(cd.toAvro()); + ColumnDefinition newCd = ColumnDefinition.fromThrift(cd.toThrift()); assert cd != newCd; assert cd.hashCode() == newCd.hashCode(); assert cd.equals(newCd); http://git-wip-us.apache.org/repos/asf/cassandra/blob/37b07935/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java b/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java index 8655a4c..084ed9b 100644 --- a/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java +++ b/test/unit/org/apache/cassandra/config/DatabaseDescriptorTest.java @@ -18,40 +18,26 @@ */ package org.apache.cassandra.config; -import static org.junit.Assert.assertNotNull; - -import org.apache.avro.specific.SpecificRecord; - import org.apache.cassandra.CleanupHelper; import org.apache.cassandra.db.migration.AddKeyspace; import org.apache.cassandra.locator.SimpleStrategy; -import org.apache.cassandra.io.SerDeUtils; +import org.apache.cassandra.thrift.InvalidRequestException; import org.junit.Test; import java.io.IOException; -import java.util.UUID; public class DatabaseDescriptorTest { - protected <D extends SpecificRecord> D serDe(D record, D newInstance) throws IOException - { - D actual = SerDeUtils.deserialize(record.getSchema(), - SerDeUtils.serialize(record), - newInstance); - assert actual.equals(record) : actual + " != " + record; - return actual; - } - @Test - public void testCFMetaDataSerialization() throws IOException, ConfigurationException + public void testCFMetaDataSerialization() throws IOException, ConfigurationException, InvalidRequestException { // test serialization of all defined test CFs. for (String table : Schema.instance.getNonSystemTables()) { for (CFMetaData cfm : Schema.instance.getTableMetaData(table).values()) { - CFMetaData cfmDupe = CFMetaData.fromAvro(serDe(cfm.toAvro(), new org.apache.cassandra.db.migration.avro.CfDef())); + CFMetaData cfmDupe = CFMetaData.fromThrift(cfm.toThrift()); assert cfmDupe != null; assert cfmDupe.equals(cfm); } @@ -65,7 +51,7 @@ public class DatabaseDescriptorTest { // Not testing round-trip on the KsDef via serDe() because maps // cannot be compared in avro. - KSMetaData ksmDupe = KSMetaData.fromAvro(ksm.toAvro()); + KSMetaData ksmDupe = KSMetaData.fromThrift(ksm.toThrift()); assert ksmDupe != null; assert ksmDupe.equals(ksm); } @@ -88,8 +74,8 @@ public class DatabaseDescriptorTest assert Schema.instance.getTableDefinition("ks0") != null; assert Schema.instance.getTableDefinition("ks1") != null; - Schema.instance.clearTableDefinition(Schema.instance.getTableDefinition("ks0"), new UUID(4096, 0)); - Schema.instance.clearTableDefinition(Schema.instance.getTableDefinition("ks1"), new UUID(4096, 0)); + Schema.instance.clearTableDefinition(Schema.instance.getTableDefinition("ks0")); + Schema.instance.clearTableDefinition(Schema.instance.getTableDefinition("ks1")); assert Schema.instance.getTableDefinition("ks0") == null; assert Schema.instance.getTableDefinition("ks1") == null; http://git-wip-us.apache.org/repos/asf/cassandra/blob/37b07935/test/unit/org/apache/cassandra/db/DefsTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/db/DefsTest.java b/test/unit/org/apache/cassandra/db/DefsTest.java index 481b07c..fbbf01b 100644 --- a/test/unit/org/apache/cassandra/db/DefsTest.java +++ b/test/unit/org/apache/cassandra/db/DefsTest.java @@ -18,15 +18,12 @@ package org.apache.cassandra.db; -import static org.junit.Assert.assertEquals; - import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; import java.util.*; import java.util.concurrent.ExecutionException; -import org.apache.avro.util.Utf8; import org.apache.cassandra.CleanupHelper; import org.apache.cassandra.Util; import org.apache.cassandra.config.*; @@ -41,39 +38,21 @@ import org.apache.cassandra.db.migration.DropKeyspace; import org.apache.cassandra.db.migration.Migration; import org.apache.cassandra.db.migration.UpdateColumnFamily; import org.apache.cassandra.db.migration.UpdateKeyspace; -import org.apache.cassandra.io.SerDeUtils; import org.apache.cassandra.io.sstable.Component; import org.apache.cassandra.io.sstable.Descriptor; import org.apache.cassandra.io.sstable.SSTableDeletingTask; import org.apache.cassandra.locator.OldNetworkTopologyStrategy; import org.apache.cassandra.locator.SimpleStrategy; -import org.apache.cassandra.net.MessagingService; +import org.apache.cassandra.thrift.CfDef; +import org.apache.cassandra.thrift.ColumnDef; import org.apache.cassandra.thrift.IndexType; -import org.apache.cassandra.utils.FBUtilities; -import org.apache.cassandra.utils.UUIDGen; -import org.junit.Test; import org.apache.cassandra.utils.ByteBufferUtil; +import org.junit.Test; public class DefsTest extends CleanupHelper { @Test - public void testZeroInjection() throws IOException - { - org.apache.cassandra.db.migration.avro.CfDef cd = new org.apache.cassandra.db.migration.avro.CfDef(); - // populate only fields that must be non-null. - cd.keyspace = new Utf8("Lest Ks"); - cd.name = new Utf8("Mest Cf"); - - org.apache.cassandra.db.migration.avro.CfDef cd2 = SerDeUtils.deserializeWithSchema(SerDeUtils.serializeWithSchema(cd), new org.apache.cassandra.db.migration.avro.CfDef()); - assert cd.equals(cd2); - // make sure some of the fields didn't get unexpected zeros put in during [de]serialize operations. - assert cd.min_compaction_threshold == null; - assert cd2.min_compaction_threshold == null; - assert cd.compaction_strategy == null; - } - - @Test public void ensureStaticCFMIdsAreLessThan1000() { assert CFMetaData.StatusCf.cfId == 0; @@ -109,22 +88,22 @@ public class DefsTest extends CleanupHelper // we'll be adding this one later. make sure it's not already there. assert cfm.getColumn_metadata().get(ByteBuffer.wrap(new byte[] { 5 })) == null; - org.apache.cassandra.db.migration.avro.CfDef cfDef = cfm.toAvro(); + CfDef cfDef = cfm.toThrift(); // add one. - org.apache.cassandra.db.migration.avro.ColumnDef addIndexDef = new org.apache.cassandra.db.migration.avro.ColumnDef(); + ColumnDef addIndexDef = new ColumnDef(); addIndexDef.index_name = "5"; - addIndexDef.index_type = org.apache.cassandra.db.migration.avro.IndexType.KEYS; + addIndexDef.index_type = IndexType.KEYS; addIndexDef.name = ByteBuffer.wrap(new byte[] { 5 }); addIndexDef.validation_class = BytesType.class.getName(); cfDef.column_metadata.add(addIndexDef); // remove one. - org.apache.cassandra.db.migration.avro.ColumnDef removeIndexDef = new org.apache.cassandra.db.migration.avro.ColumnDef(); - removeIndexDef.index_name = new Utf8("0"); - removeIndexDef.index_type = org.apache.cassandra.db.migration.avro.IndexType.KEYS; + ColumnDef removeIndexDef = new ColumnDef(); + removeIndexDef.index_name = "0"; + removeIndexDef.index_type = IndexType.KEYS; removeIndexDef.name = ByteBuffer.wrap(new byte[] { 0 }); - removeIndexDef.validation_class = new Utf8(BytesType.class.getName()); + removeIndexDef.validation_class = BytesType.class.getName(); assert cfDef.column_metadata.remove(removeIndexDef); cfm.apply(cfDef); @@ -146,10 +125,11 @@ public class DefsTest extends CleanupHelper for (String s : invalid) assert !Migration.isLegalName(s); } - + @Test public void saveAndRestore() throws IOException { + /* // verify dump and reload. UUID first = UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()); DefsTable.dumpToStorage(first); @@ -162,8 +142,9 @@ public class DefsTest extends CleanupHelper KSMetaData defined = Schema.instance.getTableDefinition(loaded.name); assert defined.equals(loaded) : String.format("%s != %s", loaded, defined); } + */ } - + @Test public void addNewCfToBogusTable() throws InterruptedException { @@ -181,52 +162,6 @@ public class DefsTest extends CleanupHelper throw new AssertionError("Unexpected exception."); } } - - @Test - public void testMigrations() throws IOException, ConfigurationException - { - // do a save. make sure it doesn't mess with the defs version. - UUID prior = Schema.instance.getVersion(); - UUID ver0 = UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()); - DefsTable.dumpToStorage(ver0); - assert Schema.instance.getVersion().equals(prior); - - // add a cf. - CFMetaData newCf1 = addTestCF("Keyspace1", "MigrationCf_1", "Migration CF"); - - Migration m1 = new AddColumnFamily(newCf1); - m1.apply(); - UUID ver1 = m1.getVersion(); - assert Schema.instance.getVersion().equals(ver1); - - // drop it. - Migration m3 = new DropColumnFamily("Keyspace1", "MigrationCf_1"); - m3.apply(); - UUID ver3 = m3.getVersion(); - assert Schema.instance.getVersion().equals(ver3); - - // now lets load the older migrations to see if that code works. - Collection<IColumn> serializedMigrations = Migration.getLocalMigrations(ver1, ver3); - assert serializedMigrations.size() == 2; - - // test deserialization of the migrations. - Migration[] reconstituded = new Migration[2]; - int i = 0; - for (IColumn col : serializedMigrations) - { - UUID version = UUIDGen.getUUID(col.name()); - reconstituded[i] = Migration.deserialize(col.value(), MessagingService.version_); - assert version.equals(reconstituded[i].getVersion()); - i++; - } - - assert m1.getClass().equals(reconstituded[0].getClass()); - assert m3.getClass().equals(reconstituded[1].getClass()); - - // verify that the row mutations are the same. rather than exposing the private fields, serialize and verify. - assert m1.serialize().equals(reconstituded[0].serialize()); - assert m3.serialize().equals(reconstituded[1].serialize()); - } @Test public void addNewCfWithNullComment() throws ConfigurationException, IOException, ExecutionException, InterruptedException @@ -473,7 +408,7 @@ public class DefsTest extends CleanupHelper KSMetaData newBadKs = KSMetaData.testMetadata(cf.ksName, SimpleStrategy.class, KSMetaData.optsWithRF(4), cf2); try { - new UpdateKeyspace(newBadKs).apply(); + new UpdateKeyspace(newBadKs.toThrift()).apply(); throw new AssertionError("Should not have been able to update a KS with a KS that described column families."); } catch (ConfigurationException ex) @@ -485,7 +420,7 @@ public class DefsTest extends CleanupHelper KSMetaData newBadKs2 = KSMetaData.testMetadata(cf.ksName + "trash", SimpleStrategy.class, KSMetaData.optsWithRF(4)); try { - new UpdateKeyspace(newBadKs2).apply(); + new UpdateKeyspace(newBadKs2.toThrift()).apply(); throw new AssertionError("Should not have been able to update a KS with an invalid KS name."); } catch (ConfigurationException ex) @@ -494,7 +429,7 @@ public class DefsTest extends CleanupHelper } KSMetaData newKs = KSMetaData.testMetadata(cf.ksName, OldNetworkTopologyStrategy.class, KSMetaData.optsWithRF(1)); - new UpdateKeyspace(newKs).apply(); + new UpdateKeyspace(newKs.toThrift()).apply(); KSMetaData newFetchedKs = Schema.instance.getKSMetaData(newKs.name); assert newFetchedKs.strategyClass.equals(newKs.strategyClass); @@ -514,8 +449,8 @@ public class DefsTest extends CleanupHelper assert Schema.instance.getCFMetaData(cf.ksName, cf.cfName) != null; // updating certain fields should fail. - org.apache.cassandra.db.migration.avro.CfDef cf_def = cf.toAvro(); - cf_def.column_metadata = new ArrayList<org.apache.cassandra.db.migration.avro.ColumnDef>(); + CfDef cf_def = cf.toThrift(); + cf_def.column_metadata = new ArrayList<ColumnDef>(); cf_def.default_validation_class ="BytesType"; cf_def.min_compaction_threshold = 5; cf_def.max_compaction_threshold = 31; @@ -561,7 +496,7 @@ public class DefsTest extends CleanupHelper cf_def.id = oldId; } - CharSequence oldStr = cf_def.name; + String oldStr = cf_def.name; try { cf_def.name = cf_def.name + "_renamed"; @@ -634,6 +569,9 @@ public class DefsTest extends CleanupHelper @Test public void testDropIndex() throws IOException, ExecutionException, InterruptedException, ConfigurationException { + // persist keyspace definition in the system table + Schema.instance.getKSMetaData("Keyspace6").toSchema(System.currentTimeMillis()).apply(); + // insert some data. save the sstable descriptor so we can make sure it's marked for delete after the drop RowMutation rm = new RowMutation("Keyspace6", ByteBufferUtil.bytes("k1")); rm.add(new QueryPath("Indexed1", null, ByteBufferUtil.bytes("notbirthdate")), ByteBufferUtil.bytes(1L), 0); @@ -649,7 +587,7 @@ public class DefsTest extends CleanupHelper ColumnDefinition cdOld = meta.getColumn_metadata().values().iterator().next(); ColumnDefinition cdNew = new ColumnDefinition(cdOld.name, cdOld.getValidator(), null, null, null); meta.columnMetadata(Collections.singletonMap(cdOld.name, cdNew)); - UpdateColumnFamily update = new UpdateColumnFamily(meta.toAvro()); + UpdateColumnFamily update = new UpdateColumnFamily(meta.toThrift()); update.apply(); // check @@ -667,4 +605,4 @@ public class DefsTest extends CleanupHelper return newCFMD; } -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cassandra/blob/37b07935/test/unit/org/apache/cassandra/db/migration/SerializationsTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/db/migration/SerializationsTest.java b/test/unit/org/apache/cassandra/db/migration/SerializationsTest.java deleted file mode 100644 index 17b8d79..0000000 --- a/test/unit/org/apache/cassandra/db/migration/SerializationsTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.apache.cassandra.db.migration; -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * - */ - - -import org.apache.cassandra.AbstractSerializationsTester; -import org.apache.cassandra.config.ConfigurationException; -import org.apache.cassandra.config.KSMetaData; -import org.apache.cassandra.config.Schema; -import org.apache.cassandra.io.SerDeUtils; -import org.apache.cassandra.utils.FBUtilities; -import org.apache.cassandra.utils.UUIDGen; -import org.apache.commons.codec.binary.Base64; -import org.junit.Test; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.UUID; - -public class SerializationsTest extends AbstractSerializationsTester -{ - private static final int ksCount = 5; - - private void testWrite() throws IOException, ConfigurationException - { - for (int i = 0; i < ksCount; i++) - { - String tableName = "Keyspace" + (i + 1); - KSMetaData ksm = Schema.instance.getKSMetaData(tableName); - UUID uuid = UUIDGen.makeType1UUIDFromHost(FBUtilities.getBroadcastAddress()); - Schema.instance.clearTableDefinition(ksm, uuid); - Migration m = new AddKeyspace(ksm); - ByteBuffer bytes = m.serialize(); - - DataOutputStream out = getOutput("db.migration." + tableName + ".bin"); - out.writeUTF(new String(Base64.encodeBase64(bytes.array()))); - out.close(); - } - } - - @Test - public void testRead() throws IOException, ConfigurationException - { - if (AbstractSerializationsTester.EXECUTE_WRITES) - testWrite(); - - for (int i = 0; i < ksCount; i++) - { - String tableName = "Keyspace" + (i + 1); - DataInputStream in = getInput("db.migration." + tableName + ".bin"); - byte[] raw = Base64.decodeBase64(in.readUTF().getBytes()); - org.apache.cassandra.db.migration.avro.Migration obj = new org.apache.cassandra.db.migration.avro.Migration(); - SerDeUtils.deserializeWithSchema(ByteBuffer.wrap(raw), obj); - in.close(); - } - } -}
