Github user JoshRosen commented on a diff in the pull request:
https://github.com/apache/spark/pull/5428#discussion_r28841856
--- Diff:
streaming/src/test/java/org/apache/spark/streaming/JavaAPISuite.java ---
@@ -1707,6 +1708,71 @@ public Integer call(String s) throws Exception {
Utils.deleteRecursively(tempDir);
}
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testContextGetOrCreate() throws InterruptedException {
+
+ final SparkConf conf = new SparkConf()
+ .setMaster("local[2]")
+ .setAppName("test")
+ .set("newContext", "true");
+
+ File emptyDir = Files.createTempDir();
+ emptyDir.deleteOnExit();
+ StreamingContextSuite contextSuite = new StreamingContextSuite();
+ String corruptedCheckpointDir =
contextSuite.createCorruptedCheckpoint();
+ String checkpointDir = contextSuite.createValidCheckpoint();
+
+ // Function to create JavaStreamingContext without any output
operations
+ // (used to detect the new context)
+ Function0<JavaStreamingContext> creatingFunc = new
Function0<JavaStreamingContext>() {
+ public JavaStreamingContext call() {
+ return new JavaStreamingContext(conf, Seconds.apply(1));
+ }
+ };
+
+ ssc = JavaStreamingContext.getOrCreate(emptyDir.getAbsolutePath(),
creatingFunc);
+ Assert.assertTrue("new context not created",
--- End diff --
Is your goal here to assert that `creatingFunc` was not called? This seems
like kind of a roundabout way of doing that. I know that Mockito makes it
pretty easy to write assertions that check the number of times that methods are
invoked; alternatively, I guess you could just stick a "number of times called"
counter in your function and check it in your assert.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]