Github user tdas commented on a diff in the pull request:
https://github.com/apache/spark/pull/5428#discussion_r28847514
--- 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 --
My knowledge of Mockito is limited, but it seemed to me that when you
configure the mock with `when...thenReturn` , you have to return a object, and
you cannot on-demand call a function to create the object to return. That is
necessary in this case, as you have to create a new StreamingContext when
getOrCreate is called, and cannot configure with `when...thenReturn` an
already created context.
That said, I think you are right about the current way be roundabout. I was
trying to avoid having an extra flag var to signify called or not. But that
would make it easier to understand. I will change it.
---
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]