-
Notifications
You must be signed in to change notification settings - Fork 28.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
150 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
external/akka/src/test/java/org/apache/spark/streaming/akka/JavaAkkaUtilsSuite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.spark.streaming.akka; | ||
|
||
import akka.actor.ActorSystem; | ||
import akka.actor.Props; | ||
import akka.actor.SupervisorStrategy; | ||
import org.apache.spark.streaming.Duration; | ||
import org.apache.spark.streaming.api.java.JavaStreamingContext; | ||
import org.junit.Test; | ||
|
||
import org.apache.spark.api.java.function.Function0; | ||
import org.apache.spark.storage.StorageLevel; | ||
import org.apache.spark.streaming.api.java.JavaReceiverInputDStream; | ||
|
||
public class JavaAkkaUtilsSuite { | ||
|
||
@Test // tests the API, does not actually test data receiving | ||
public void testAkkaUtils() { | ||
JavaStreamingContext jsc = new JavaStreamingContext("local[2]", "test", new Duration(1000)); | ||
try { | ||
JavaReceiverInputDStream<String> test1 = AkkaUtils.<String>createStream( | ||
jsc, Props.create(JavaTestActor.class), "test"); | ||
JavaReceiverInputDStream<String> test2 = AkkaUtils.<String>createStream( | ||
jsc, Props.create(JavaTestActor.class), "test", StorageLevel.MEMORY_AND_DISK_SER_2()); | ||
JavaReceiverInputDStream<String> test3 = AkkaUtils.<String>createStream( | ||
jsc, | ||
Props.create(JavaTestActor.class), | ||
"test", StorageLevel.MEMORY_AND_DISK_SER_2(), | ||
new ActorSystemCreatorForTest(), | ||
SupervisorStrategy.defaultStrategy()); | ||
} finally { | ||
jsc.stop(); | ||
} | ||
} | ||
} | ||
|
||
class ActorSystemCreatorForTest implements Function0<ActorSystem> { | ||
@Override | ||
public ActorSystem call() { | ||
return null; | ||
} | ||
} | ||
|
||
|
||
class JavaTestActor extends JavaActorReceiver { | ||
@Override | ||
public void onReceive(Object message) throws Exception { | ||
store((String) message); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
external/akka/src/test/scala/org/apache/spark/streaming/akka/AkkaUtilsSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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.spark.streaming.akka | ||
|
||
import akka.actor.{Props, SupervisorStrategy} | ||
|
||
import org.apache.spark.SparkFunSuite | ||
import org.apache.spark.storage.StorageLevel | ||
import org.apache.spark.streaming.{Seconds, StreamingContext} | ||
import org.apache.spark.streaming.dstream.ReceiverInputDStream | ||
|
||
class AkkaUtilsSuite extends SparkFunSuite { | ||
|
||
test("createStream") { | ||
val ssc: StreamingContext = new StreamingContext("local[2]", "test", Seconds(1000)) | ||
try { | ||
// tests the API, does not actually test data receiving | ||
val test1: ReceiverInputDStream[String] = AkkaUtils.createStream( | ||
ssc, Props[TestActor](), "test") | ||
val test2: ReceiverInputDStream[String] = AkkaUtils.createStream( | ||
ssc, Props[TestActor](), "test", StorageLevel.MEMORY_AND_DISK_SER_2) | ||
val test3: ReceiverInputDStream[String] = AkkaUtils.createStream( | ||
ssc, | ||
Props[TestActor](), | ||
"test", | ||
StorageLevel.MEMORY_AND_DISK_SER_2, | ||
supervisorStrategy = SupervisorStrategy.defaultStrategy) | ||
val test4: ReceiverInputDStream[String] = AkkaUtils.createStream( | ||
ssc, Props[TestActor](), "test", StorageLevel.MEMORY_AND_DISK_SER_2, () => null) | ||
val test5: ReceiverInputDStream[String] = AkkaUtils.createStream( | ||
ssc, Props[TestActor](), "test", StorageLevel.MEMORY_AND_DISK_SER_2, () => null) | ||
val test6: ReceiverInputDStream[String] = AkkaUtils.createStream( | ||
ssc, | ||
Props[TestActor](), | ||
"test", | ||
StorageLevel.MEMORY_AND_DISK_SER_2, | ||
() => null, | ||
SupervisorStrategy.defaultStrategy) | ||
} finally { | ||
ssc.stop() | ||
} | ||
} | ||
} | ||
|
||
class TestActor extends ActorReceiver { | ||
override def receive: Receive = { | ||
case m: String => store(m) | ||
} | ||
} |