You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ma...@apache.org on 2021/09/21 10:29:03 UTC
[cassandra] branch cassandra-4.0 updated: CASSANDRA-16942 followup;
move SSTableExport schema loading tests to a separate class
This is an automated email from the ASF dual-hosted git repository.
marcuse pushed a commit to branch cassandra-4.0
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/cassandra-4.0 by this push:
new 86aaf22 CASSANDRA-16942 followup; move SSTableExport schema loading tests to a separate class
86aaf22 is described below
commit 86aaf22f15290fac1b5f94843c9a2c9d1c6d56fd
Author: Marcus Eriksson <ma...@apache.org>
AuthorDate: Tue Sep 21 10:37:15 2021 +0200
CASSANDRA-16942 followup; move SSTableExport schema loading tests to a separate class
Patch by marcuse; reviewed by Berenguer Blasi for CASSANDRA-16942
---
...st.java => SSTableExportSchemaLoadingTest.java} | 118 ++++------------
.../apache/cassandra/tools/SSTableExportTest.java | 155 +--------------------
2 files changed, 32 insertions(+), 241 deletions(-)
diff --git a/test/unit/org/apache/cassandra/tools/SSTableExportTest.java b/test/unit/org/apache/cassandra/tools/SSTableExportSchemaLoadingTest.java
similarity index 52%
copy from test/unit/org/apache/cassandra/tools/SSTableExportTest.java
copy to test/unit/org/apache/cassandra/tools/SSTableExportSchemaLoadingTest.java
index ecd5f6e..f8d0f99 100644
--- a/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
+++ b/test/unit/org/apache/cassandra/tools/SSTableExportSchemaLoadingTest.java
@@ -28,11 +28,8 @@ import org.junit.Test;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
-import org.apache.cassandra.tools.ToolRunner.ToolResult;
import org.assertj.core.api.Assertions;
-import static org.hamcrest.CoreMatchers.containsStringIgnoringCase;
-import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -41,7 +38,11 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-public class SSTableExportTest extends OfflineToolUtils
+/**
+ * Moved to separate class from SSTableExportTest to avoid schema getting loaded before
+ * running a test where we don't expect the schema to be loaded
+ */
+public class SSTableExportSchemaLoadingTest extends OfflineToolUtils
{
private static final ObjectMapper mapper = new ObjectMapper();
private static final TypeReference<List<Map<String, Object>>> jacksonListOfMapsType = new TypeReference<List<Map<String, Object>>>() {};
@@ -54,132 +55,71 @@ public class SSTableExportTest extends OfflineToolUtils
}
@Test
- public void testNoArgsPrintsHelp()
- {
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class);
- assertThat(tool.getStdout(), containsStringIgnoringCase("usage:"));
- assertThat(tool.getCleanedStderr(), containsStringIgnoringCase("You must supply exactly one sstable"));
- assertThat(tool.getCleanedStderr(), not(containsStringIgnoringCase("before the -k/-x options")));
- assertEquals(1, tool.getExitCode());
- assertPostTestEnv(false);
- }
-
- @Test
- public void testMaybeChangeDocs()
- {
- // If you added, modified options or help, please update docs if necessary
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class);
- String help = "usage: sstabledump <sstable file path> <options>\n" +
- " \n" +
- "Dump contents of given SSTable to standard output in JSON format.\n" +
- " -d CQL row per line internal representation\n" +
- " -e enumerate partition keys only\n" +
- " -k <arg> List of included partition keys\n" +
- " -l Output json lines, by partition\n" +
- " -t Print raw timestamps instead of iso8601 date strings\n" +
- " -x <arg> List of excluded partition keys\n";
- Assertions.assertThat(tool.getStdout()).isEqualTo(help);
- assertPostTestEnv(false);
- }
-
- @Test
- public void testWrongArgFailsAndPrintsHelp()
- {
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, "--debugwrong", sstable);
- assertThat(tool.getStdout(), containsStringIgnoringCase("usage:"));
- assertThat(tool.getCleanedStderr(), containsStringIgnoringCase("Unrecognized option"));
- assertEquals(1, tool.getExitCode());
- assertPostTestEnv(false);
- }
-
- @Test
- public void testPKArgOutOfOrder()
- {
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, "-k", "0", sstable);
- assertThat(tool.getStdout(), containsStringIgnoringCase("usage:"));
- assertThat(tool.getCleanedStderr(), containsStringIgnoringCase("You must supply exactly one sstable"));
- assertThat(tool.getCleanedStderr(), containsStringIgnoringCase("before the -k/-x options"));
- assertEquals(1, tool.getExitCode());
- assertPostTestEnv(false);
- }
-
- @Test
- public void testExcludePKArgOutOfOrder()
- {
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, "-x", "0", sstable);
- assertThat(tool.getStdout(), containsStringIgnoringCase("usage:"));
- assertThat(tool.getCleanedStderr(), containsStringIgnoringCase("You must supply exactly one sstable"));
- assertThat(tool.getCleanedStderr(), containsStringIgnoringCase("before the -k/-x options"));
- assertEquals(1, tool.getExitCode());
- assertPostTestEnv(false);
- }
-
- @Test
public void testDefaultCall() throws IOException
{
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable);
+ ToolRunner.ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable);
List<Map<String, Object>> parsed = mapper.readValue(tool.getStdout(), jacksonListOfMapsType);
assertNotNull(tool.getStdout(), parsed.get(0).get("partition"));
assertNotNull(tool.getStdout(), parsed.get(0).get("rows"));
Assertions.assertThat(tool.getCleanedStderr()).isEmpty();
tool.assertOnExitCode();
- assertPostTestEnv(true);
+ assertPostTestEnv();
}
@Test
public void testCQLRowArg()
{
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-d");
+ ToolRunner.ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-d");
assertThat(tool.getStdout(), startsWith("[0]"));
Assertions.assertThat(tool.getCleanedStderr()).isEmpty();
tool.assertOnExitCode();
- assertPostTestEnv(true);
+ assertPostTestEnv();
}
@Test
public void testPKOnlyArg()
{
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-e");
+ ToolRunner.ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-e");
assertEquals(tool.getStdout(), "[ [ \"0\" ], [ \"1\" ], [ \"2\" ], [ \"3\" ], [ \"4\" ]\n]", tool.getStdout());
Assertions.assertThat(tool.getCleanedStderr()).isEmpty();
tool.assertOnExitCode();
- assertPostTestEnv(true);
+ assertPostTestEnv();
}
@Test
public void testPKArg() throws IOException
{
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-k", "0");
+ ToolRunner.ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-k", "0");
assertKeys(tool, "0");
- assertPostTestEnv(true);
+ assertPostTestEnv();
}
@Test
public void testMultiplePKArg() throws IOException
{
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-k", "0", "2");
+ ToolRunner.ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-k", "0", "2");
assertKeys(tool, "0", "2");
- assertPostTestEnv(true);
+ assertPostTestEnv();
}
@Test
public void testExcludePKArg() throws IOException
{
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-x", "0");
+ ToolRunner.ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-x", "0");
assertKeys(tool, "1", "2", "3", "4");
- assertPostTestEnv(true);
+ assertPostTestEnv();
}
@Test
public void testMultipleExcludePKArg() throws IOException
{
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-x", "0", "2");
+ ToolRunner.ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-x", "0", "2");
assertKeys(tool, "1", "3", "4");
- assertPostTestEnv(true);
+ assertPostTestEnv();
}
@SuppressWarnings("rawtypes")
- private void assertKeys(ToolResult tool, String... expectedKeys) throws IOException
+ private void assertKeys(ToolRunner.ToolResult tool, String... expectedKeys) throws IOException
{
List<Map<String, Object>> parsed = mapper.readValue(tool.getStdout(), jacksonListOfMapsType);
String[] actualKeys = parsed.stream()
@@ -196,21 +136,21 @@ public class SSTableExportTest extends OfflineToolUtils
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testTSFormatArg() throws IOException
{
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-t");
+ ToolRunner.ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-t");
List<Map<String, Object>> parsed = mapper.readValue(tool.getStdout(), jacksonListOfMapsType);
assertEquals(tool.getStdout(),
"1445008632854000",
((Map) ((List<Map>) parsed.get(0).get("rows")).get(0).get("liveness_info")).get("tstamp"));
Assertions.assertThat(tool.getCleanedStderr()).isEmpty();
tool.assertOnExitCode();
- assertPostTestEnv(true);
+ assertPostTestEnv();
}
@Test
@SuppressWarnings({ "rawtypes", "DynamicRegexReplaceableByCompiledPattern" })
public void testJSONLineArg() throws IOException
{
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-l");
+ ToolRunner.ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-l");
try
{
mapper.readValue(tool.getStdout(), jacksonListOfMapsType);
@@ -233,24 +173,16 @@ public class SSTableExportTest extends OfflineToolUtils
assertThat(tool.getStdout(), startsWith("{\""));
Assertions.assertThat(tool.getCleanedStderr()).isEmpty();
tool.assertOnExitCode();
- assertPostTestEnv(true);
+ assertPostTestEnv();
}
/**
* Runs post-test assertions about loaded classed and started threads.
*
- * @param maybeLoadsSchema {@code true} if the test may or may not have loaded the schema depending on the JVM,
- * {@code false} if the test shoudln't load the schema in any case. Note that a test not loading the schema can
- * still end with the schema loaded if a previous test already loaded it, so we should always run first the tests
- * that don't load the schema, and then the ones that may or may not load it. We also need to use the
*/
- private void assertPostTestEnv(boolean maybeLoadsSchema)
+ private void assertPostTestEnv()
{
assertNoUnexpectedThreadsStarted(null, OPTIONAL_THREADS_WITH_SCHEMA);
- // schema loading seems to depend on the JVM version,
- // so we only verify the cases where we are sure it's not loaded
- if (!maybeLoadsSchema)
- assertSchemaNotLoaded();
assertCLSMNotLoaded();
assertSystemKSNotLoaded();
assertKeyspaceNotLoaded();
diff --git a/test/unit/org/apache/cassandra/tools/SSTableExportTest.java b/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
index ecd5f6e..6b5395c 100644
--- a/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
+++ b/test/unit/org/apache/cassandra/tools/SSTableExportTest.java
@@ -19,32 +19,20 @@
package org.apache.cassandra.tools;
import java.io.IOException;
-import java.util.List;
-import java.util.Map;
import org.junit.BeforeClass;
import org.junit.Test;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.exc.MismatchedInputException;
import org.apache.cassandra.tools.ToolRunner.ToolResult;
import org.assertj.core.api.Assertions;
import static org.hamcrest.CoreMatchers.containsStringIgnoringCase;
import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.CoreMatchers.startsWith;
-import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
public class SSTableExportTest extends OfflineToolUtils
{
- private static final ObjectMapper mapper = new ObjectMapper();
- private static final TypeReference<List<Map<String, Object>>> jacksonListOfMapsType = new TypeReference<List<Map<String, Object>>>() {};
private static String sstable;
@BeforeClass
@@ -61,7 +49,7 @@ public class SSTableExportTest extends OfflineToolUtils
assertThat(tool.getCleanedStderr(), containsStringIgnoringCase("You must supply exactly one sstable"));
assertThat(tool.getCleanedStderr(), not(containsStringIgnoringCase("before the -k/-x options")));
assertEquals(1, tool.getExitCode());
- assertPostTestEnv(false);
+ assertPostTestEnv();
}
@Test
@@ -79,7 +67,7 @@ public class SSTableExportTest extends OfflineToolUtils
" -t Print raw timestamps instead of iso8601 date strings\n" +
" -x <arg> List of excluded partition keys\n";
Assertions.assertThat(tool.getStdout()).isEqualTo(help);
- assertPostTestEnv(false);
+ assertPostTestEnv();
}
@Test
@@ -89,7 +77,7 @@ public class SSTableExportTest extends OfflineToolUtils
assertThat(tool.getStdout(), containsStringIgnoringCase("usage:"));
assertThat(tool.getCleanedStderr(), containsStringIgnoringCase("Unrecognized option"));
assertEquals(1, tool.getExitCode());
- assertPostTestEnv(false);
+ assertPostTestEnv();
}
@Test
@@ -100,7 +88,7 @@ public class SSTableExportTest extends OfflineToolUtils
assertThat(tool.getCleanedStderr(), containsStringIgnoringCase("You must supply exactly one sstable"));
assertThat(tool.getCleanedStderr(), containsStringIgnoringCase("before the -k/-x options"));
assertEquals(1, tool.getExitCode());
- assertPostTestEnv(false);
+ assertPostTestEnv();
}
@Test
@@ -111,146 +99,17 @@ public class SSTableExportTest extends OfflineToolUtils
assertThat(tool.getCleanedStderr(), containsStringIgnoringCase("You must supply exactly one sstable"));
assertThat(tool.getCleanedStderr(), containsStringIgnoringCase("before the -k/-x options"));
assertEquals(1, tool.getExitCode());
- assertPostTestEnv(false);
+ assertPostTestEnv();
}
- @Test
- public void testDefaultCall() throws IOException
- {
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable);
- List<Map<String, Object>> parsed = mapper.readValue(tool.getStdout(), jacksonListOfMapsType);
- assertNotNull(tool.getStdout(), parsed.get(0).get("partition"));
- assertNotNull(tool.getStdout(), parsed.get(0).get("rows"));
- Assertions.assertThat(tool.getCleanedStderr()).isEmpty();
- tool.assertOnExitCode();
- assertPostTestEnv(true);
- }
-
- @Test
- public void testCQLRowArg()
- {
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-d");
- assertThat(tool.getStdout(), startsWith("[0]"));
- Assertions.assertThat(tool.getCleanedStderr()).isEmpty();
- tool.assertOnExitCode();
- assertPostTestEnv(true);
- }
-
- @Test
- public void testPKOnlyArg()
- {
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-e");
- assertEquals(tool.getStdout(), "[ [ \"0\" ], [ \"1\" ], [ \"2\" ], [ \"3\" ], [ \"4\" ]\n]", tool.getStdout());
- Assertions.assertThat(tool.getCleanedStderr()).isEmpty();
- tool.assertOnExitCode();
- assertPostTestEnv(true);
- }
-
- @Test
- public void testPKArg() throws IOException
- {
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-k", "0");
- assertKeys(tool, "0");
- assertPostTestEnv(true);
- }
-
- @Test
- public void testMultiplePKArg() throws IOException
- {
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-k", "0", "2");
- assertKeys(tool, "0", "2");
- assertPostTestEnv(true);
- }
-
- @Test
- public void testExcludePKArg() throws IOException
- {
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-x", "0");
- assertKeys(tool, "1", "2", "3", "4");
- assertPostTestEnv(true);
- }
-
- @Test
- public void testMultipleExcludePKArg() throws IOException
- {
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-x", "0", "2");
- assertKeys(tool, "1", "3", "4");
- assertPostTestEnv(true);
- }
-
- @SuppressWarnings("rawtypes")
- private void assertKeys(ToolResult tool, String... expectedKeys) throws IOException
- {
- List<Map<String, Object>> parsed = mapper.readValue(tool.getStdout(), jacksonListOfMapsType);
- String[] actualKeys = parsed.stream()
- .map(x -> (Map) x.get("partition"))
- .map(x -> (List) x.get("key"))
- .map(x -> (String) x.get(0))
- .toArray(String[]::new);
- assertArrayEquals(expectedKeys, actualKeys);
- Assertions.assertThat(tool.getCleanedStderr()).isEmpty();
- tool.assertOnExitCode();
- }
-
- @Test
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public void testTSFormatArg() throws IOException
- {
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-t");
- List<Map<String, Object>> parsed = mapper.readValue(tool.getStdout(), jacksonListOfMapsType);
- assertEquals(tool.getStdout(),
- "1445008632854000",
- ((Map) ((List<Map>) parsed.get(0).get("rows")).get(0).get("liveness_info")).get("tstamp"));
- Assertions.assertThat(tool.getCleanedStderr()).isEmpty();
- tool.assertOnExitCode();
- assertPostTestEnv(true);
- }
-
- @Test
- @SuppressWarnings({ "rawtypes", "DynamicRegexReplaceableByCompiledPattern" })
- public void testJSONLineArg() throws IOException
- {
- ToolResult tool = ToolRunner.invokeClass(SSTableExport.class, sstable, "-l");
- try
- {
- mapper.readValue(tool.getStdout(), jacksonListOfMapsType);
- fail("Shouldn't be able to deserialize that output, now it's not a collection anymore.");
- }
- catch (MismatchedInputException e)
- {
- assertThat(e.getMessage(), startsWith("Cannot deserialize"));
- }
-
- int parsedCount = 0;
- for (String jsonLine : tool.getStdout().split("\\R"))
- {
- Map line = mapper.readValue(jsonLine, Map.class);
- assertTrue(jsonLine, line.containsKey("partition"));
- parsedCount++;
- }
-
- assertEquals(tool.getStdout(), 5, parsedCount);
- assertThat(tool.getStdout(), startsWith("{\""));
- Assertions.assertThat(tool.getCleanedStderr()).isEmpty();
- tool.assertOnExitCode();
- assertPostTestEnv(true);
- }
/**
* Runs post-test assertions about loaded classed and started threads.
- *
- * @param maybeLoadsSchema {@code true} if the test may or may not have loaded the schema depending on the JVM,
- * {@code false} if the test shoudln't load the schema in any case. Note that a test not loading the schema can
- * still end with the schema loaded if a previous test already loaded it, so we should always run first the tests
- * that don't load the schema, and then the ones that may or may not load it. We also need to use the
*/
- private void assertPostTestEnv(boolean maybeLoadsSchema)
+ private void assertPostTestEnv()
{
assertNoUnexpectedThreadsStarted(null, OPTIONAL_THREADS_WITH_SCHEMA);
- // schema loading seems to depend on the JVM version,
- // so we only verify the cases where we are sure it's not loaded
- if (!maybeLoadsSchema)
- assertSchemaNotLoaded();
+ assertSchemaNotLoaded();
assertCLSMNotLoaded();
assertSystemKSNotLoaded();
assertKeyspaceNotLoaded();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org