Repository: cassandra Updated Branches: refs/heads/trunk 858004791 -> 9797511c5
http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/schema/SchemaKeyspaceTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/schema/SchemaKeyspaceTest.java b/test/unit/org/apache/cassandra/schema/SchemaKeyspaceTest.java index d686fdb..2f83498 100644 --- a/test/unit/org/apache/cassandra/schema/SchemaKeyspaceTest.java +++ b/test/unit/org/apache/cassandra/schema/SchemaKeyspaceTest.java @@ -35,6 +35,7 @@ import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.ColumnDefinition; import org.apache.cassandra.config.Schema; +import org.apache.cassandra.config.SchemaConstants; import org.apache.cassandra.cql3.QueryProcessor; import org.apache.cassandra.cql3.UntypedResultSet; import org.apache.cassandra.db.ColumnFamilyStore; @@ -188,15 +189,15 @@ public class SchemaKeyspaceTest // Test schema conversion Mutation rm = SchemaKeyspace.makeCreateTableMutation(keyspace, cfm, FBUtilities.timestampMicros()).build(); - PartitionUpdate serializedCf = rm.getPartitionUpdate(Schema.instance.getId(SchemaKeyspace.NAME, SchemaKeyspace.TABLES)); - PartitionUpdate serializedCD = rm.getPartitionUpdate(Schema.instance.getId(SchemaKeyspace.NAME, SchemaKeyspace.COLUMNS)); + PartitionUpdate serializedCf = rm.getPartitionUpdate(Schema.instance.getId(SchemaConstants.SCHEMA_KEYSPACE_NAME, SchemaKeyspace.TABLES)); + PartitionUpdate serializedCD = rm.getPartitionUpdate(Schema.instance.getId(SchemaConstants.SCHEMA_KEYSPACE_NAME, SchemaKeyspace.COLUMNS)); - UntypedResultSet.Row tableRow = QueryProcessor.resultify(String.format("SELECT * FROM %s.%s", SchemaKeyspace.NAME, SchemaKeyspace.TABLES), + UntypedResultSet.Row tableRow = QueryProcessor.resultify(String.format("SELECT * FROM %s.%s", SchemaConstants.SCHEMA_KEYSPACE_NAME, SchemaKeyspace.TABLES), UnfilteredRowIterators.filter(serializedCf.unfilteredIterator(), FBUtilities.nowInSeconds())) .one(); TableParams params = SchemaKeyspace.createTableParamsFromRow(tableRow); - UntypedResultSet columnsRows = QueryProcessor.resultify(String.format("SELECT * FROM %s.%s", SchemaKeyspace.NAME, SchemaKeyspace.COLUMNS), + UntypedResultSet columnsRows = QueryProcessor.resultify(String.format("SELECT * FROM %s.%s", SchemaConstants.SCHEMA_KEYSPACE_NAME, SchemaKeyspace.COLUMNS), UnfilteredRowIterators.filter(serializedCD.unfilteredIterator(), FBUtilities.nowInSeconds())); Set<ColumnDefinition> columns = new HashSet<>(); for (UntypedResultSet.Row row : columnsRows) http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/security/EncryptionUtilsTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/security/EncryptionUtilsTest.java b/test/unit/org/apache/cassandra/security/EncryptionUtilsTest.java index be37f45..70b327e 100644 --- a/test/unit/org/apache/cassandra/security/EncryptionUtilsTest.java +++ b/test/unit/org/apache/cassandra/security/EncryptionUtilsTest.java @@ -31,8 +31,10 @@ import javax.crypto.ShortBufferException; import org.junit.Assert; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; +import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.config.TransparentDataEncryptionOptions; import org.apache.cassandra.io.compress.ICompressor; import org.apache.cassandra.io.compress.LZ4Compressor; @@ -40,6 +42,12 @@ import org.apache.cassandra.io.util.RandomAccessReader; public class EncryptionUtilsTest { + @BeforeClass + public static void initDD() + { + DatabaseDescriptor.daemonInitialization(); + } + final Random random = new Random(); ICompressor compressor; TransparentDataEncryptionOptions tdeOptions; http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/service/DataResolverTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/service/DataResolverTest.java b/test/unit/org/apache/cassandra/service/DataResolverTest.java index 156bd66..93415ba 100644 --- a/test/unit/org/apache/cassandra/service/DataResolverTest.java +++ b/test/unit/org/apache/cassandra/service/DataResolverTest.java @@ -31,6 +31,7 @@ import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.ColumnDefinition; +import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.cql3.ColumnIdentifier; import org.apache.cassandra.db.*; import org.apache.cassandra.db.marshal.ByteType; @@ -79,6 +80,7 @@ public class DataResolverTest @BeforeClass public static void defineSchema() throws ConfigurationException { + DatabaseDescriptor.daemonInitialization(); CFMetaData cfMetadata = CFMetaData.Builder.create(KEYSPACE1, CF_STANDARD) .addPartitionKey("key", BytesType.instance) .addClusteringColumn("col1", AsciiType.instance) http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/service/LeaveAndBootstrapTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/service/LeaveAndBootstrapTest.java b/test/unit/org/apache/cassandra/service/LeaveAndBootstrapTest.java index efab615..19f0b7a 100644 --- a/test/unit/org/apache/cassandra/service/LeaveAndBootstrapTest.java +++ b/test/unit/org/apache/cassandra/service/LeaveAndBootstrapTest.java @@ -33,6 +33,7 @@ import org.junit.Test; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.Util; import org.apache.cassandra.Util.PartitionerSwitcher; +import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.config.Schema; import org.apache.cassandra.db.SystemKeyspace; import org.apache.cassandra.dht.IPartitioner; @@ -61,6 +62,7 @@ public class LeaveAndBootstrapTest @BeforeClass public static void defineSchema() throws Exception { + DatabaseDescriptor.daemonInitialization(); partitionerSwitcher = Util.switchPartitioner(partitioner); SchemaLoader.loadSchema(); SchemaLoader.schemaDefinition("LeaveAndBootstrapTest"); http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/service/MoveTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/service/MoveTest.java b/test/unit/org/apache/cassandra/service/MoveTest.java index 53365aa..05757c0 100644 --- a/test/unit/org/apache/cassandra/service/MoveTest.java +++ b/test/unit/org/apache/cassandra/service/MoveTest.java @@ -84,6 +84,7 @@ public class MoveTest @BeforeClass public static void setup() throws ConfigurationException { + DatabaseDescriptor.daemonInitialization(); oldPartitioner = StorageService.instance.setPartitionerUnsafe(partitioner); SchemaLoader.loadSchema(); SchemaLoader.schemaDefinition("MoveTest"); http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/service/NativeTransportServiceTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/service/NativeTransportServiceTest.java b/test/unit/org/apache/cassandra/service/NativeTransportServiceTest.java index d0e291a..04cc9dd 100644 --- a/test/unit/org/apache/cassandra/service/NativeTransportServiceTest.java +++ b/test/unit/org/apache/cassandra/service/NativeTransportServiceTest.java @@ -25,6 +25,7 @@ import java.util.stream.IntStream; import com.google.common.collect.Sets; import org.junit.After; +import org.junit.BeforeClass; import org.junit.Test; import org.apache.cassandra.config.DatabaseDescriptor; @@ -37,6 +38,11 @@ import static org.junit.Assert.assertTrue; public class NativeTransportServiceTest { + @BeforeClass + public static void setupDD() + { + DatabaseDescriptor.daemonInitialization(); + } @After public void resetConfig() http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/service/RemoveTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/service/RemoveTest.java b/test/unit/org/apache/cassandra/service/RemoveTest.java index 4c26fc5..0ef9b9c 100644 --- a/test/unit/org/apache/cassandra/service/RemoveTest.java +++ b/test/unit/org/apache/cassandra/service/RemoveTest.java @@ -50,6 +50,11 @@ import static org.junit.Assert.assertTrue; public class RemoveTest { + static + { + DatabaseDescriptor.daemonInitialization(); + } + static final IPartitioner partitioner = RandomPartitioner.instance; StorageService ss = StorageService.instance; TokenMetadata tmd = ss.getTokenMetadata(); http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/service/SerializationsTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/service/SerializationsTest.java b/test/unit/org/apache/cassandra/service/SerializationsTest.java index 847bcea..4df112a 100644 --- a/test/unit/org/apache/cassandra/service/SerializationsTest.java +++ b/test/unit/org/apache/cassandra/service/SerializationsTest.java @@ -31,6 +31,7 @@ import org.junit.Test; import org.apache.cassandra.AbstractSerializationsTester; import org.apache.cassandra.Util; import org.apache.cassandra.Util.PartitionerSwitcher; +import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.dht.IPartitioner; import org.apache.cassandra.dht.RandomPartitioner; import org.apache.cassandra.dht.Range; @@ -56,6 +57,7 @@ public class SerializationsTest extends AbstractSerializationsTester @BeforeClass public static void defineSchema() throws Exception { + DatabaseDescriptor.daemonInitialization(); partitionerSwitcher = Util.switchPartitioner(RandomPartitioner.instance); RANDOM_UUID = UUID.fromString("b5c3d033-75aa-4c2f-a819-947aac7a0c54"); FULL_RANGE = new Range<>(Util.testPartitioner().getMinimumToken(), Util.testPartitioner().getMinimumToken()); http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/service/StartupChecksTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/service/StartupChecksTest.java b/test/unit/org/apache/cassandra/service/StartupChecksTest.java index d32b1b1..224f3d9 100644 --- a/test/unit/org/apache/cassandra/service/StartupChecksTest.java +++ b/test/unit/org/apache/cassandra/service/StartupChecksTest.java @@ -27,6 +27,7 @@ import org.junit.*; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.config.SchemaConstants; import org.apache.cassandra.db.*; import org.apache.cassandra.exceptions.StartupException; import org.apache.cassandra.io.util.FileUtils; @@ -50,9 +51,9 @@ public class StartupChecksTest @Before public void setup() throws IOException { - for (ColumnFamilyStore cfs : Keyspace.open(SystemKeyspace.NAME).getColumnFamilyStores()) + for (ColumnFamilyStore cfs : Keyspace.open(SchemaConstants.SYSTEM_KEYSPACE_NAME).getColumnFamilyStores()) cfs.clearUnsafe(); - for (File dataDir : Directories.getKSChildDirectories(SystemKeyspace.NAME)) + for (File dataDir : Directories.getKSChildDirectories(SchemaConstants.SYSTEM_KEYSPACE_NAME)) FileUtils.deleteRecursive(dataDir); File dataDir = new File(DatabaseDescriptor.getAllDataFileLocations()[0]); http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/service/StorageProxyTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/service/StorageProxyTest.java b/test/unit/org/apache/cassandra/service/StorageProxyTest.java index 42eb1f5..bdf45fe 100644 --- a/test/unit/org/apache/cassandra/service/StorageProxyTest.java +++ b/test/unit/org/apache/cassandra/service/StorageProxyTest.java @@ -78,6 +78,7 @@ public class StorageProxyTest @BeforeClass public static void beforeClass() throws Throwable { + DatabaseDescriptor.daemonInitialization(); DatabaseDescriptor.getHintsDirectory().mkdir(); TokenMetadata tmd = StorageService.instance.getTokenMetadata(); tmd.updateNormalToken(token("1"), InetAddress.getByName("127.0.0.1")); http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java b/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java index 498fc73..297d19d 100644 --- a/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java +++ b/test/unit/org/apache/cassandra/service/StorageServiceServerTest.java @@ -35,6 +35,7 @@ import org.junit.runner.RunWith; import org.apache.cassandra.OrderedJUnit4ClassRunner; import org.apache.cassandra.SchemaLoader; import org.apache.cassandra.config.DatabaseDescriptor; +import org.apache.cassandra.config.SchemaConstants; import org.apache.cassandra.schema.KeyspaceMetadata; import org.apache.cassandra.config.Schema; import org.apache.cassandra.db.Keyspace; @@ -63,6 +64,7 @@ public class StorageServiceServerTest @BeforeClass public static void setUp() throws ConfigurationException { + DatabaseDescriptor.daemonInitialization(); IEndpointSnitch snitch = new PropertyFileSnitch(); DatabaseDescriptor.setEndpointSnitch(snitch); Keyspace.setInitialized(); @@ -173,14 +175,14 @@ public class StorageServiceServerTest public void testTableSnapshot() throws IOException { // no need to insert extra data, even an "empty" database will have a little information in the system keyspace - StorageService.instance.takeTableSnapshot(SchemaKeyspace.NAME, SchemaKeyspace.KEYSPACES, UUID.randomUUID().toString()); + StorageService.instance.takeTableSnapshot(SchemaConstants.SCHEMA_KEYSPACE_NAME, SchemaKeyspace.KEYSPACES, UUID.randomUUID().toString()); } @Test public void testSnapshot() throws IOException { // no need to insert extra data, even an "empty" database will have a little information in the system keyspace - StorageService.instance.takeSnapshot(UUID.randomUUID().toString(), SchemaKeyspace.NAME); + StorageService.instance.takeSnapshot(UUID.randomUUID().toString(), SchemaConstants.SCHEMA_KEYSPACE_NAME); } @Test http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/service/pager/PagingStateTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/service/pager/PagingStateTest.java b/test/unit/org/apache/cassandra/service/pager/PagingStateTest.java index 98fa959..0ae6d9a 100644 --- a/test/unit/org/apache/cassandra/service/pager/PagingStateTest.java +++ b/test/unit/org/apache/cassandra/service/pager/PagingStateTest.java @@ -21,10 +21,12 @@ package org.apache.cassandra.service.pager; import java.nio.ByteBuffer; +import org.junit.BeforeClass; import org.junit.Test; import org.apache.cassandra.config.CFMetaData; import org.apache.cassandra.config.ColumnDefinition; +import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.cql3.ColumnIdentifier; import org.apache.cassandra.db.*; import org.apache.cassandra.db.rows.*; @@ -37,6 +39,12 @@ import static org.junit.Assert.assertTrue; public class PagingStateTest { + @BeforeClass + public static void setupDD() + { + DatabaseDescriptor.daemonInitialization(); + } + private PagingState makeSomePagingState(int protocolVersion) { CFMetaData metadata = CFMetaData.Builder.create("ks", "tbl") http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/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 75429e9..8f3061a 100644 --- a/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java +++ b/test/unit/org/apache/cassandra/streaming/StreamingTransferTest.java @@ -62,6 +62,11 @@ public class StreamingTransferTest { private static final Logger logger = LoggerFactory.getLogger(StreamingTransferTest.class); + static + { + DatabaseDescriptor.daemonInitialization(); + } + public static final InetAddress LOCAL = FBUtilities.getBroadcastAddress(); public static final String KEYSPACE1 = "StreamingTransferTest1"; public static final String CF_STANDARD = "Standard1"; http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/streaming/compression/CompressedInputStreamTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/streaming/compression/CompressedInputStreamTest.java b/test/unit/org/apache/cassandra/streaming/compression/CompressedInputStreamTest.java index 07281c9..c0fc277 100644 --- a/test/unit/org/apache/cassandra/streaming/compression/CompressedInputStreamTest.java +++ b/test/unit/org/apache/cassandra/streaming/compression/CompressedInputStreamTest.java @@ -20,7 +20,10 @@ package org.apache.cassandra.streaming.compression; import java.io.*; import java.util.*; +import org.junit.BeforeClass; import org.junit.Test; + +import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.db.ClusteringComparator; import org.apache.cassandra.db.marshal.BytesType; import org.apache.cassandra.io.compress.CompressedSequentialWriter; @@ -42,6 +45,12 @@ import static org.junit.Assert.fail; */ public class CompressedInputStreamTest { + @BeforeClass + public static void setupDD() + { + DatabaseDescriptor.daemonInitialization(); + } + @Test public void testCompressedRead() throws Exception { http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/tools/BulkLoaderTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/tools/BulkLoaderTest.java b/test/unit/org/apache/cassandra/tools/BulkLoaderTest.java new file mode 100644 index 0000000..104f288 --- /dev/null +++ b/test/unit/org/apache/cassandra/tools/BulkLoaderTest.java @@ -0,0 +1,66 @@ +/* + * 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. + */ + +package org.apache.cassandra.tools; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.datastax.driver.core.exceptions.NoHostAvailableException; +import org.apache.cassandra.OrderedJUnit4ClassRunner; + +import static org.junit.Assert.fail; + +@RunWith(OrderedJUnit4ClassRunner.class) +public class BulkLoaderTest extends ToolsTester +{ + @Test + public void testBulkLoader_NoArgs() + { + runTool(1, "org.apache.cassandra.tools.BulkLoader"); + assertNoUnexpectedThreadsStarted(null, null); + assertSchemaNotLoaded(); + assertCLSMNotLoaded(); + assertSystemKSNotLoaded(); + assertKeyspaceNotLoaded(); + assertServerNotLoaded(); + } + + @Test + public void testBulkLoader_WithArgs() throws Exception + { + try + { + runTool(0, "org.apache.cassandra.tools.BulkLoader", "-d", "127.9.9.1", sstableDirName("legacy_sstables", "legacy_ma_simple")); + fail(); + } + catch (RuntimeException e) + { + if (!(e.getCause() instanceof BulkLoadException)) + throw e; + if (!(e.getCause().getCause() instanceof NoHostAvailableException)) + throw e; + } + assertNoUnexpectedThreadsStarted(null, new String[]{"globalEventExecutor-1-1", "globalEventExecutor-1-2"}); + assertSchemaNotLoaded(); + assertCLSMNotLoaded(); + assertSystemKSNotLoaded(); + assertKeyspaceNotLoaded(); + assertServerNotLoaded(); + } +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/tools/GetVersionTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/tools/GetVersionTest.java b/test/unit/org/apache/cassandra/tools/GetVersionTest.java new file mode 100644 index 0000000..84e2f49 --- /dev/null +++ b/test/unit/org/apache/cassandra/tools/GetVersionTest.java @@ -0,0 +1,40 @@ +/* + * 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. + */ + +package org.apache.cassandra.tools; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.cassandra.OrderedJUnit4ClassRunner; + +@RunWith(OrderedJUnit4ClassRunner.class) +public class GetVersionTest extends ToolsTester +{ + @Test + public void testGetVersion() + { + runTool(0, "org.apache.cassandra.tools.GetVersion"); + assertNoUnexpectedThreadsStarted(null, null); + assertSchemaNotLoaded(); + assertCLSMNotLoaded(); + assertSystemKSNotLoaded(); + assertKeyspaceNotLoaded(); + assertServerNotLoaded(); + } +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/tools/SSTableExpiredBlockersTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/tools/SSTableExpiredBlockersTest.java b/test/unit/org/apache/cassandra/tools/SSTableExpiredBlockersTest.java new file mode 100644 index 0000000..1c09174 --- /dev/null +++ b/test/unit/org/apache/cassandra/tools/SSTableExpiredBlockersTest.java @@ -0,0 +1,50 @@ +/* + * 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. + */ + +package org.apache.cassandra.tools; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.cassandra.OrderedJUnit4ClassRunner; + +@RunWith(OrderedJUnit4ClassRunner.class) +public class SSTableExpiredBlockersTest extends ToolsTester +{ + @Test + public void testSSTableExpiredBlockers_NoArgs() + { + runTool(1, "org.apache.cassandra.tools.SSTableExpiredBlockers"); + assertNoUnexpectedThreadsStarted(null, null); + assertSchemaNotLoaded(); + assertCLSMNotLoaded(); + assertSystemKSNotLoaded(); + assertKeyspaceNotLoaded(); + assertServerNotLoaded(); + } + + @Test + public void testSSTableExpiredBlockers_WithArgs() + { + // returns exit code 1, since no sstables are there + runTool(1, "org.apache.cassandra.tools.SSTableExpiredBlockers", "system_schema", "tables"); + assertNoUnexpectedThreadsStarted(EXPECTED_THREADS_WITH_SCHEMA, OPTIONAL_THREADS_WITH_SCHEMA); + assertSchemaLoaded(); + assertServerNotLoaded(); + } +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/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 new file mode 100644 index 0000000..0e49bb5 --- /dev/null +++ b/test/unit/org/apache/cassandra/tools/SSTableExportTest.java @@ -0,0 +1,51 @@ +/* + * 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. + */ + +package org.apache.cassandra.tools; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.cassandra.OrderedJUnit4ClassRunner; + +@RunWith(OrderedJUnit4ClassRunner.class) +public class SSTableExportTest extends ToolsTester +{ + @Test + public void testSSTableExport_NoArgs() + { + runTool(1, "org.apache.cassandra.tools.SSTableExport"); + assertNoUnexpectedThreadsStarted(null, OPTIONAL_THREADS_WITH_SCHEMA); + assertSchemaNotLoaded(); + assertCLSMNotLoaded(); + assertSystemKSNotLoaded(); + assertKeyspaceNotLoaded(); + assertServerNotLoaded(); + } + + @Test + public void testSSTableExport_WithArgs() throws Exception + { + runTool(0, "org.apache.cassandra.tools.SSTableExport", findOneSSTable("legacy_sstables", "legacy_ma_simple")); + assertNoUnexpectedThreadsStarted(null, OPTIONAL_THREADS_WITH_SCHEMA); + assertSchemaNotLoaded(); + assertCLSMNotLoaded(); + assertSystemKSNotLoaded(); + assertServerNotLoaded(); + } +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/tools/SSTableLevelResetterTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/tools/SSTableLevelResetterTest.java b/test/unit/org/apache/cassandra/tools/SSTableLevelResetterTest.java new file mode 100644 index 0000000..b70fcef --- /dev/null +++ b/test/unit/org/apache/cassandra/tools/SSTableLevelResetterTest.java @@ -0,0 +1,49 @@ +/* + * 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. + */ + +package org.apache.cassandra.tools; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.cassandra.OrderedJUnit4ClassRunner; + +@RunWith(OrderedJUnit4ClassRunner.class) +public class SSTableLevelResetterTest extends ToolsTester +{ + @Test + public void testSSTableLevelResetter_NoArgs() + { + runTool(1, "org.apache.cassandra.tools.SSTableLevelResetter"); + assertNoUnexpectedThreadsStarted(null, null); + assertSchemaNotLoaded(); + assertCLSMNotLoaded(); + assertSystemKSNotLoaded(); + assertKeyspaceNotLoaded(); + assertServerNotLoaded(); + } + + @Test + public void testSSTableLevelResetter_WithArgs() + { + runTool(0, "org.apache.cassandra.tools.SSTableLevelResetter", "--really-reset", "system_schema", "tables"); + assertNoUnexpectedThreadsStarted(EXPECTED_THREADS_WITH_SCHEMA, OPTIONAL_THREADS_WITH_SCHEMA); + assertSchemaLoaded(); + assertServerNotLoaded(); + } +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/tools/SSTableMetadataViewerTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/tools/SSTableMetadataViewerTest.java b/test/unit/org/apache/cassandra/tools/SSTableMetadataViewerTest.java new file mode 100644 index 0000000..8b782e3 --- /dev/null +++ b/test/unit/org/apache/cassandra/tools/SSTableMetadataViewerTest.java @@ -0,0 +1,52 @@ +/* + * 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. + */ + +package org.apache.cassandra.tools; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.cassandra.OrderedJUnit4ClassRunner; + +@RunWith(OrderedJUnit4ClassRunner.class) +public class SSTableMetadataViewerTest extends ToolsTester +{ + @Test + public void testSSTableOfflineRelevel_NoArgs() + { + runTool(1, "org.apache.cassandra.tools.SSTableMetadataViewer"); + assertNoUnexpectedThreadsStarted(null, null); + assertSchemaNotLoaded(); + assertCLSMNotLoaded(); + assertSystemKSNotLoaded(); + assertKeyspaceNotLoaded(); + assertServerNotLoaded(); + } + + @Test + public void testSSTableOfflineRelevel_WithArgs() + { + runTool(0, "org.apache.cassandra.tools.SSTableMetadataViewer", "ks", "tab"); + assertNoUnexpectedThreadsStarted(null, OPTIONAL_THREADS_WITH_SCHEMA); + assertSchemaNotLoaded(); + assertCLSMNotLoaded(); + assertSystemKSNotLoaded(); + assertKeyspaceNotLoaded(); + assertServerNotLoaded(); + } +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/tools/SSTableOfflineRelevelTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/tools/SSTableOfflineRelevelTest.java b/test/unit/org/apache/cassandra/tools/SSTableOfflineRelevelTest.java new file mode 100644 index 0000000..0c6eecf --- /dev/null +++ b/test/unit/org/apache/cassandra/tools/SSTableOfflineRelevelTest.java @@ -0,0 +1,50 @@ +/* + * 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. + */ + +package org.apache.cassandra.tools; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.cassandra.OrderedJUnit4ClassRunner; + +@RunWith(OrderedJUnit4ClassRunner.class) +public class SSTableOfflineRelevelTest extends ToolsTester +{ + @Test + public void testSSTableOfflineRelevel_NoArgs() + { + runTool(1, "org.apache.cassandra.tools.SSTableOfflineRelevel"); + assertNoUnexpectedThreadsStarted(null, null); + assertSchemaNotLoaded(); + assertCLSMNotLoaded(); + assertSystemKSNotLoaded(); + assertKeyspaceNotLoaded(); + assertServerNotLoaded(); + } + + @Test + public void testSSTableOfflineRelevel_WithArgs() + { + // Note: SSTableOfflineRelevel exits with code 1 if no sstables to relevel have been found + runTool(1, "org.apache.cassandra.tools.SSTableOfflineRelevel", "system_schema", "tables"); + assertNoUnexpectedThreadsStarted(EXPECTED_THREADS_WITH_SCHEMA, OPTIONAL_THREADS_WITH_SCHEMA); + assertSchemaLoaded(); + assertServerNotLoaded(); + } +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/tools/SSTableRepairedAtSetterTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/tools/SSTableRepairedAtSetterTest.java b/test/unit/org/apache/cassandra/tools/SSTableRepairedAtSetterTest.java new file mode 100644 index 0000000..9dece5a --- /dev/null +++ b/test/unit/org/apache/cassandra/tools/SSTableRepairedAtSetterTest.java @@ -0,0 +1,52 @@ +/* + * 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. + */ + +package org.apache.cassandra.tools; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.cassandra.OrderedJUnit4ClassRunner; + +@RunWith(OrderedJUnit4ClassRunner.class) +public class SSTableRepairedAtSetterTest extends ToolsTester +{ + @Test + public void testSSTableRepairedAtSetter_NoArgs() + { + runTool(1, "org.apache.cassandra.tools.SSTableRepairedAtSetter"); + assertNoUnexpectedThreadsStarted(null, null); + assertSchemaNotLoaded(); + assertCLSMNotLoaded(); + assertSystemKSNotLoaded(); + assertKeyspaceNotLoaded(); + assertServerNotLoaded(); + } + + @Test + public void testSSTableRepairedAtSetter_WithArgs() throws Exception + { + runTool(0, "org.apache.cassandra.tools.SSTableRepairedAtSetter", "--really-set", "--is-repaired", findOneSSTable("legacy_sstables", "legacy_ma_simple")); + assertNoUnexpectedThreadsStarted(null, OPTIONAL_THREADS_WITH_SCHEMA); + assertSchemaNotLoaded(); + assertCLSMNotLoaded(); + assertSystemKSNotLoaded(); + assertKeyspaceNotLoaded(); + assertServerNotLoaded(); + } +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/tools/StandaloneSSTableUtilTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/tools/StandaloneSSTableUtilTest.java b/test/unit/org/apache/cassandra/tools/StandaloneSSTableUtilTest.java new file mode 100644 index 0000000..2026a79 --- /dev/null +++ b/test/unit/org/apache/cassandra/tools/StandaloneSSTableUtilTest.java @@ -0,0 +1,49 @@ +/* + * 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. + */ + +package org.apache.cassandra.tools; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.cassandra.OrderedJUnit4ClassRunner; + +@RunWith(OrderedJUnit4ClassRunner.class) +public class StandaloneSSTableUtilTest extends ToolsTester +{ + @Test + public void testStandaloneSSTableUtil_NoArgs() + { + runTool(1, "org.apache.cassandra.tools.StandaloneSSTableUtil"); + assertNoUnexpectedThreadsStarted(null, null); + assertSchemaNotLoaded(); + assertCLSMNotLoaded(); + assertSystemKSNotLoaded(); + assertKeyspaceNotLoaded(); + assertServerNotLoaded(); + } + + @Test + public void testStandaloneSSTableUtil_WithArgs() + { + runTool(0, "org.apache.cassandra.tools.StandaloneSSTableUtil", "--debug", "-c", "system_schema", "tables"); + assertNoUnexpectedThreadsStarted(EXPECTED_THREADS_WITH_SCHEMA, OPTIONAL_THREADS_WITH_SCHEMA); + assertSchemaLoaded(); + assertServerNotLoaded(); + } +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/tools/StandaloneScrubberTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/tools/StandaloneScrubberTest.java b/test/unit/org/apache/cassandra/tools/StandaloneScrubberTest.java new file mode 100644 index 0000000..6aef5eb --- /dev/null +++ b/test/unit/org/apache/cassandra/tools/StandaloneScrubberTest.java @@ -0,0 +1,49 @@ +/* + * 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. + */ + +package org.apache.cassandra.tools; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.cassandra.OrderedJUnit4ClassRunner; + +@RunWith(OrderedJUnit4ClassRunner.class) +public class StandaloneScrubberTest extends ToolsTester +{ + @Test + public void testStandaloneScrubber_NoArgs() + { + runTool(1, "org.apache.cassandra.tools.StandaloneScrubber"); + assertNoUnexpectedThreadsStarted(null, null); + assertSchemaNotLoaded(); + assertCLSMNotLoaded(); + assertSystemKSNotLoaded(); + assertKeyspaceNotLoaded(); + assertServerNotLoaded(); + } + + @Test + public void testStandaloneScrubber_WithArgs() + { + runTool(0, "org.apache.cassandra.tools.StandaloneScrubber", "--debug", "system_schema", "tables"); + assertNoUnexpectedThreadsStarted(EXPECTED_THREADS_WITH_SCHEMA, OPTIONAL_THREADS_WITH_SCHEMA); + assertSchemaLoaded(); + assertServerNotLoaded(); + } +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/tools/StandaloneSplitterTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/tools/StandaloneSplitterTest.java b/test/unit/org/apache/cassandra/tools/StandaloneSplitterTest.java new file mode 100644 index 0000000..c0f8593 --- /dev/null +++ b/test/unit/org/apache/cassandra/tools/StandaloneSplitterTest.java @@ -0,0 +1,52 @@ +/* + * 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. + */ + +package org.apache.cassandra.tools; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.cassandra.OrderedJUnit4ClassRunner; + +@RunWith(OrderedJUnit4ClassRunner.class) +public class StandaloneSplitterTest extends ToolsTester +{ + @BeforeClass + public static void before() + { + // the legacy tables use a different partitioner :( + // (Don't use ByteOrderedPartitioner.class.getName() as that would initialize the class and work + // against the goal of this test to check classes and threads initialized by the tool.) + System.setProperty("cassandra.partitioner", "org.apache.cassandra.dht.ByteOrderedPartitioner"); + } + + @Test + public void testStandaloneSplitter_NoArgs() + { + runTool(1, "org.apache.cassandra.tools.StandaloneSplitter"); + assertNoUnexpectedThreadsStarted(null, null); + assertSchemaNotLoaded(); + assertCLSMNotLoaded(); + assertSystemKSNotLoaded(); + assertKeyspaceNotLoaded(); + assertServerNotLoaded(); + } + + // Note: StandaloneSplitter modifies sstables +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/tools/StandaloneUpgraderTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/tools/StandaloneUpgraderTest.java b/test/unit/org/apache/cassandra/tools/StandaloneUpgraderTest.java new file mode 100644 index 0000000..f703a49 --- /dev/null +++ b/test/unit/org/apache/cassandra/tools/StandaloneUpgraderTest.java @@ -0,0 +1,49 @@ +/* + * 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. + */ + +package org.apache.cassandra.tools; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.cassandra.OrderedJUnit4ClassRunner; + +@RunWith(OrderedJUnit4ClassRunner.class) +public class StandaloneUpgraderTest extends ToolsTester +{ + @Test + public void testStandaloneUpgrader_NoArgs() + { + runTool(1, "org.apache.cassandra.tools.StandaloneUpgrader"); + assertNoUnexpectedThreadsStarted(null, null); + assertSchemaNotLoaded(); + assertCLSMNotLoaded(); + assertSystemKSNotLoaded(); + assertKeyspaceNotLoaded(); + assertServerNotLoaded(); + } + + @Test + public void testStandaloneUpgrader_WithArgs() + { + runTool(0, "org.apache.cassandra.tools.StandaloneUpgrader", "--debug", "system_schema", "tables"); + assertNoUnexpectedThreadsStarted(EXPECTED_THREADS_WITH_SCHEMA, OPTIONAL_THREADS_WITH_SCHEMA); + assertSchemaLoaded(); + assertServerNotLoaded(); + } +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/tools/StandaloneVerifierTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/tools/StandaloneVerifierTest.java b/test/unit/org/apache/cassandra/tools/StandaloneVerifierTest.java new file mode 100644 index 0000000..38418f3 --- /dev/null +++ b/test/unit/org/apache/cassandra/tools/StandaloneVerifierTest.java @@ -0,0 +1,49 @@ +/* + * 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. + */ + +package org.apache.cassandra.tools; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import org.apache.cassandra.OrderedJUnit4ClassRunner; + +@RunWith(OrderedJUnit4ClassRunner.class) +public class StandaloneVerifierTest extends ToolsTester +{ + @Test + public void testStandaloneVerifier_NoArgs() + { + runTool(1, "org.apache.cassandra.tools.StandaloneVerifier"); + assertNoUnexpectedThreadsStarted(null, null); + assertSchemaNotLoaded(); + assertCLSMNotLoaded(); + assertSystemKSNotLoaded(); + assertKeyspaceNotLoaded(); + assertServerNotLoaded(); + } + + @Test + public void testStandaloneVerifier_WithArgs() + { + runTool(0, "org.apache.cassandra.tools.StandaloneVerifier", "--debug", "system_schema", "tables"); + assertNoUnexpectedThreadsStarted(EXPECTED_THREADS_WITH_SCHEMA, OPTIONAL_THREADS_WITH_SCHEMA); + assertSchemaLoaded(); + assertServerNotLoaded(); + } +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/tools/ToolsTester.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/tools/ToolsTester.java b/test/unit/org/apache/cassandra/tools/ToolsTester.java new file mode 100644 index 0000000..5094a53 --- /dev/null +++ b/test/unit/org/apache/cassandra/tools/ToolsTester.java @@ -0,0 +1,296 @@ +/* + * 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. + */ + +package org.apache.cassandra.tools; + +import java.io.File; +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.lang.management.ThreadInfo; +import java.lang.management.ThreadMXBean; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.Permission; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +import org.apache.commons.io.FileUtils; +import org.junit.BeforeClass; + +import org.slf4j.LoggerFactory; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Base unit test class for standalone tools + */ +public abstract class ToolsTester +{ + private static List<ThreadInfo> initialThreads; + + static final String[] EXPECTED_THREADS_WITH_SCHEMA = { + "NativePoolCleaner", + "COMMIT-LOG-ALLOCATOR", + "COMMIT-LOG-WRITER", + "PerDiskMemtableFlushWriter_0:[1-9]", + "MemtablePostFlush:[1-9]", + "MemtableFlushWriter:[1-9]", + "MemtableReclaimMemory:[1-9]", + }; + static final String[] OPTIONAL_THREADS_WITH_SCHEMA = { + "ScheduledTasks:[1-9]", + "OptionalTasks:[1-9]", + "Reference-Reaper:[1-9]", + "LocalPool-Cleaner:[1-9]", + "CacheCleanupExecutor:[1-9]", + "CompactionExecutor:[1-9]", + "ValidationExecutor:[1-9]", + "NonPeriodicTasks:[1-9]", + "Sampler:[1-9]", + "SecondaryIndexManagement:[1-9]", + "Strong-Reference-Leak-Detector:[1-9]", + "Background_Reporter:[1-9]", + "EXPIRING-MAP-REAPER:[1-9]", + }; + + public void assertNoUnexpectedThreadsStarted(String[] expectedThreadNames, String[] optionalThreadNames) + { + ThreadMXBean threads = ManagementFactory.getThreadMXBean(); + + Set<String> initial = initialThreads + .stream() + .map(ThreadInfo::getThreadName) + .collect(Collectors.toSet()); + + Set<String> current = Arrays.stream(threads.getThreadInfo(threads.getAllThreadIds())) + .map(ThreadInfo::getThreadName) + .collect(Collectors.toSet()); + + List<Pattern> expected = expectedThreadNames != null + ? Arrays.stream(expectedThreadNames).map(Pattern::compile).collect(Collectors.toList()) + : Collections.emptyList(); + + List<Pattern> optional = optionalThreadNames != null + ? Arrays.stream(optionalThreadNames).map(Pattern::compile).collect(Collectors.toList()) + : Collections.emptyList(); + + current.removeAll(initial); + + List<Pattern> notPresent = expected.stream() + .filter(threadNamePattern -> !current.stream().anyMatch(threadName -> threadNamePattern.matcher(threadName).matches())) + .collect(Collectors.toList()); + + Set<String> remain = current.stream() + .filter(threadName -> expected.stream().anyMatch(pattern -> pattern.matcher(threadName).matches())) + .filter(threadName -> optional.stream().anyMatch(pattern -> pattern.matcher(threadName).matches())) + .collect(Collectors.toSet()); + + if (!current.isEmpty()) + System.err.println("Unexpected thread names: " + remain); + if (!notPresent.isEmpty()) + System.err.println("Mandatory thread missing: " + notPresent); + + assertTrue("Wrong thread status", remain.isEmpty() && notPresent.isEmpty()); + } + + public void assertSchemaNotLoaded() + { + assertClassNotLoaded("org.apache.cassandra.config.Schema"); + } + + public void assertSchemaLoaded() + { + assertClassLoaded("org.apache.cassandra.config.Schema"); + } + + public void assertKeyspaceNotLoaded() + { + assertClassNotLoaded("org.apache.cassandra.db.Keyspace"); + } + + public void assertKeyspaceLoaded() + { + assertClassLoaded("org.apache.cassandra.db.Keyspace"); + } + + public void assertServerNotLoaded() + { + assertClassNotLoaded("org.apache.cassandra.transport.Server"); + } + + public void assertSystemKSNotLoaded() + { + assertClassNotLoaded("org.apache.cassandra.db.SystemKeyspace"); + } + + public void assertCLSMNotLoaded() + { + assertClassNotLoaded("org.apache.cassandra.db.commitlog.CommitLogSegmentManager"); + } + + public void assertClassLoaded(String clazz) + { + assertClassLoadedStatus(clazz, true); + } + + public void assertClassNotLoaded(String clazz) + { + assertClassLoadedStatus(clazz, false); + } + + private void assertClassLoadedStatus(String clazz, boolean expected) + { + for (ClassLoader cl = Thread.currentThread().getContextClassLoader(); cl != null; cl = cl.getParent()) + { + try + { + Method mFindLoadedClass = ClassLoader.class.getDeclaredMethod("findLoadedClass", String.class); + mFindLoadedClass.setAccessible(true); + boolean loaded = mFindLoadedClass.invoke(cl, clazz) != null; + + if (expected) + { + if (loaded) + return; + } + else + assertFalse(clazz + " has been loaded", loaded); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + } + + if (expected) + fail(clazz + " has not been loaded"); + } + + public void runTool(int expectedExitCode, String clazz, String... args) + { + try + { + // install security manager to get informed about the exit-code + System.setSecurityManager(new SecurityManager() + { + public void checkExit(int status) + { + throw new SystemExitException(status); + } + + public void checkPermission(Permission perm) + { + } + + public void checkPermission(Permission perm, Object context) + { + } + }); + + try + { + Class.forName(clazz).getDeclaredMethod("main", String[].class).invoke(null, (Object) args); + } + catch (InvocationTargetException e) + { + Throwable cause = e.getCause(); + if (cause instanceof Error) + throw (Error) cause; + if (cause instanceof RuntimeException) + throw (RuntimeException) cause; + throw e; + } + + assertEquals("Unexpected exit code", expectedExitCode, 0); + } + catch (SystemExitException e) + { + assertEquals("Unexpected exit code", expectedExitCode, e.status); + } + catch (InvocationTargetException e) + { + throw new RuntimeException(e.getTargetException()); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + finally + { + // uninstall security manager + System.setSecurityManager(null); + } + } + + @BeforeClass + public static void setupTester() + { + System.setProperty("cassandra.partitioner", "org.apache.cassandra.dht.Murmur3Partitioner"); + + // may start an async appender + LoggerFactory.getLogger(ToolsTester.class); + + ThreadMXBean threads = ManagementFactory.getThreadMXBean(); + initialThreads = Arrays.asList(threads.getThreadInfo(threads.getAllThreadIds())); + } + + public static class SystemExitException extends Error + { + public final int status; + + public SystemExitException(int status) + { + this.status = status; + } + } + + public static String findOneSSTable(String ks, String cf) throws IOException + { + File cfDir = sstableDir(ks, cf); + File[] sstableFiles = cfDir.listFiles((file) -> file.isFile() && file.getName().endsWith("-Data.db")); + return sstableFiles[0].getAbsolutePath(); + } + + public static String sstableDirName(String ks, String cf) throws IOException + { + return sstableDir(ks, cf).getAbsolutePath(); + } + + public static File sstableDir(String ks, String cf) throws IOException + { + File dataDir = copySSTables(); + File ksDir = new File(dataDir, ks); + File[] cfDirs = ksDir.listFiles((dir, name) -> cf.equals(name) || name.startsWith(cf + '-')); + return cfDirs[0]; + } + + public static File copySSTables() throws IOException + { + File dataDir = new File("build/test/cassandra/data"); + File srcDir = new File("test/data/legacy-sstables/ma"); + FileUtils.copyDirectory(new File(srcDir, "legacy_tables"), new File(dataDir, "legacy_sstables")); + return dataDir; + } +} http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/tracing/TracingTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/tracing/TracingTest.java b/test/unit/org/apache/cassandra/tracing/TracingTest.java index 30521c0..ab6d03d 100644 --- a/test/unit/org/apache/cassandra/tracing/TracingTest.java +++ b/test/unit/org/apache/cassandra/tracing/TracingTest.java @@ -26,13 +26,20 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import org.junit.BeforeClass; import org.junit.Test; +import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.utils.progress.ProgressEvent; import org.apache.cassandra.utils.progress.ProgressListener; public final class TracingTest { + @BeforeClass + public static void setupDD() + { + DatabaseDescriptor.daemonInitialization(); + } @Test public void test() http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java b/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java index 2be7b08..44c434d 100644 --- a/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java +++ b/test/unit/org/apache/cassandra/transport/ProtocolErrorTest.java @@ -19,9 +19,11 @@ package org.apache.cassandra.transport; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.transport.messages.ErrorMessage; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; import java.util.ArrayList; @@ -31,6 +33,12 @@ import static org.apache.cassandra.transport.Message.Direction.*; public class ProtocolErrorTest { + @BeforeClass + public static void setupDD() + { + DatabaseDescriptor.daemonInitialization(); + } + @Test public void testInvalidProtocolVersion() throws Exception { http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/triggers/TriggerExecutorTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/triggers/TriggerExecutorTest.java b/test/unit/org/apache/cassandra/triggers/TriggerExecutorTest.java index 36efabd..8c0e5f2 100644 --- a/test/unit/org/apache/cassandra/triggers/TriggerExecutorTest.java +++ b/test/unit/org/apache/cassandra/triggers/TriggerExecutorTest.java @@ -19,10 +19,12 @@ package org.apache.cassandra.triggers; import java.util.*; +import org.junit.BeforeClass; import org.junit.Test; import org.apache.cassandra.Util; import org.apache.cassandra.config.CFMetaData; +import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.db.*; import org.apache.cassandra.db.rows.*; import org.apache.cassandra.db.marshal.UTF8Type; @@ -40,6 +42,12 @@ import static org.junit.Assert.assertTrue; public class TriggerExecutorTest { + @BeforeClass + public static void setupDD() + { + DatabaseDescriptor.daemonInitialization(); + } + @Test public void sameKeySameCfColumnFamilies() throws ConfigurationException, InvalidRequestException { http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/utils/JVMStabilityInspectorTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/utils/JVMStabilityInspectorTest.java b/test/unit/org/apache/cassandra/utils/JVMStabilityInspectorTest.java index eb8dbf9..7101dbc 100644 --- a/test/unit/org/apache/cassandra/utils/JVMStabilityInspectorTest.java +++ b/test/unit/org/apache/cassandra/utils/JVMStabilityInspectorTest.java @@ -21,6 +21,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.net.SocketException; +import org.junit.BeforeClass; import org.junit.Test; import org.apache.cassandra.config.Config; @@ -32,6 +33,12 @@ import static org.junit.Assert.assertTrue; public class JVMStabilityInspectorTest { + @BeforeClass + public static void initDD() + { + DatabaseDescriptor.daemonInitialization(); + } + @Test public void testKill() throws Exception { http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/utils/MerkleTreesTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/utils/MerkleTreesTest.java b/test/unit/org/apache/cassandra/utils/MerkleTreesTest.java index ec8fd68..8d7284c 100644 --- a/test/unit/org/apache/cassandra/utils/MerkleTreesTest.java +++ b/test/unit/org/apache/cassandra/utils/MerkleTreesTest.java @@ -26,6 +26,8 @@ import com.google.common.collect.AbstractIterator; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; + +import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.dht.*; import org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken; import org.apache.cassandra.io.util.DataInputBuffer; @@ -60,6 +62,7 @@ public class MerkleTreesTest @BeforeClass public static void setUp() { + DatabaseDescriptor.daemonInitialization(); StorageService.instance.setPartitionerUnsafe(partitioner); } @Before http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/utils/SerializationsTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/utils/SerializationsTest.java b/test/unit/org/apache/cassandra/utils/SerializationsTest.java index cf50769..ac5a6a7 100644 --- a/test/unit/org/apache/cassandra/utils/SerializationsTest.java +++ b/test/unit/org/apache/cassandra/utils/SerializationsTest.java @@ -22,10 +22,12 @@ import java.io.DataInputStream; import java.io.IOException; import org.junit.Assert; +import org.junit.BeforeClass; import org.junit.Test; import org.apache.cassandra.AbstractSerializationsTester; import org.apache.cassandra.Util; +import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.db.DecoratedKey; import org.apache.cassandra.db.marshal.Int32Type; import org.apache.cassandra.io.util.DataInputPlus.DataInputStreamPlus; @@ -38,6 +40,12 @@ import java.io.FileInputStream; public class SerializationsTest extends AbstractSerializationsTester { + @BeforeClass + public static void initDD() + { + DatabaseDescriptor.daemonInitialization(); + } + private static void testBloomFilterWrite(boolean offheap, boolean oldBfHashOrder) throws IOException { IPartitioner partitioner = Util.testPartitioner(); http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/utils/concurrent/AbstractTransactionalTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/utils/concurrent/AbstractTransactionalTest.java b/test/unit/org/apache/cassandra/utils/concurrent/AbstractTransactionalTest.java index f0c850d..5a20d67 100644 --- a/test/unit/org/apache/cassandra/utils/concurrent/AbstractTransactionalTest.java +++ b/test/unit/org/apache/cassandra/utils/concurrent/AbstractTransactionalTest.java @@ -18,14 +18,21 @@ */ package org.apache.cassandra.utils.concurrent; +import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; import junit.framework.Assert; +import org.apache.cassandra.config.DatabaseDescriptor; @Ignore public abstract class AbstractTransactionalTest { + @BeforeClass + public static void setupDD() + { + DatabaseDescriptor.daemonInitialization(); + } protected abstract TestableTransaction newTest() throws Exception; http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/test/unit/org/apache/cassandra/utils/memory/BufferPoolTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/utils/memory/BufferPoolTest.java b/test/unit/org/apache/cassandra/utils/memory/BufferPoolTest.java index 208cd32..74889a1 100644 --- a/test/unit/org/apache/cassandra/utils/memory/BufferPoolTest.java +++ b/test/unit/org/apache/cassandra/utils/memory/BufferPoolTest.java @@ -25,9 +25,11 @@ import java.util.concurrent.*; import org.junit.After; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; +import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.io.compress.BufferType; import org.apache.cassandra.io.util.RandomAccessReader; @@ -35,6 +37,12 @@ import static org.junit.Assert.*; public class BufferPoolTest { + @BeforeClass + public static void setupDD() + { + DatabaseDescriptor.daemonInitialization(); + } + @Before public void setUp() { http://git-wip-us.apache.org/repos/asf/cassandra/blob/9797511c/tools/stress/src/org/apache/cassandra/stress/Stress.java ---------------------------------------------------------------------- diff --git a/tools/stress/src/org/apache/cassandra/stress/Stress.java b/tools/stress/src/org/apache/cassandra/stress/Stress.java index 581ec0c..6382904 100644 --- a/tools/stress/src/org/apache/cassandra/stress/Stress.java +++ b/tools/stress/src/org/apache/cassandra/stress/Stress.java @@ -21,6 +21,7 @@ import java.io.*; import java.net.Socket; import java.net.SocketException; +import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.stress.settings.StressSettings; import org.apache.cassandra.utils.FBUtilities; import org.apache.cassandra.utils.WindowsTimer; @@ -71,6 +72,8 @@ public final class Stress { try { + DatabaseDescriptor.toolInitialization(); + final StressSettings settings; try {
