mirror of
https://github.com/wassname/ray.git
synced 2026-06-30 20:00:22 +08:00
[Streaming] Add configuration with owner config. (#6687)
This commit is contained in:
+34
@@ -0,0 +1,34 @@
|
||||
package org.ray.streaming.runtime;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
|
||||
public abstract class BaseUnitTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(BaseUnitTest.class);
|
||||
|
||||
@BeforeClass
|
||||
public void setUp() {
|
||||
TestHelper.setUTFlag();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public void tearDown() {
|
||||
TestHelper.clearUTFlag();
|
||||
}
|
||||
|
||||
@BeforeMethod
|
||||
public void testBegin(Method method) {
|
||||
LOG.info(">>>>>>>>>>>>>>>>>>>> Test case: " + method.getName() + " began >>>>>>>>>>>>>>>>>>>>");
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
public void testEnd(Method method) {
|
||||
LOG.info(">>>>>>>>>>>>>>>>>>>> Test case: " + method.getName() + " end >>>>>>>>>>>>>>>>>>");
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package org.ray.streaming.runtime;
|
||||
|
||||
public class TestHelper {
|
||||
|
||||
private static volatile boolean UT_FLAG = false;
|
||||
|
||||
public static void setUTFlag() {
|
||||
UT_FLAG = true;
|
||||
}
|
||||
|
||||
public static void clearUTFlag() {
|
||||
UT_FLAG = false;
|
||||
}
|
||||
|
||||
public static boolean isUT() {
|
||||
return UT_FLAG;
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package org.ray.streaming.runtime.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.aeonbits.owner.ConfigFactory;
|
||||
import org.nustaq.serialization.FSTConfiguration;
|
||||
import org.ray.streaming.runtime.BaseUnitTest;
|
||||
import org.ray.streaming.runtime.config.global.CommonConfig;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class ConfigTest extends BaseUnitTest {
|
||||
|
||||
@Test
|
||||
public void testBaseFunc() {
|
||||
// conf using
|
||||
CommonConfig commonConfig = ConfigFactory.create(CommonConfig.class);
|
||||
Assert.assertTrue(commonConfig.jobId().equals("default-job-id"));
|
||||
|
||||
// override conf
|
||||
Map<String, String> customConf = new HashMap<>();
|
||||
customConf.put(CommonConfig.JOB_ID, "111");
|
||||
CommonConfig commonConfig2 = ConfigFactory.create(CommonConfig.class, customConf);
|
||||
Assert.assertTrue(commonConfig2.jobId().equals("111"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapTransformation() {
|
||||
Map<String, String> conf = new HashMap<>();
|
||||
String testValue = "222";
|
||||
conf.put(CommonConfig.JOB_ID, testValue);
|
||||
|
||||
StreamingConfig config = new StreamingConfig(conf);
|
||||
Map<String, String> wholeConfigMap = config.getMap();
|
||||
|
||||
Assert.assertTrue(wholeConfigMap.get(CommonConfig.JOB_ID).equals(testValue));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomConfKeeping() {
|
||||
Map<String, String> conf = new HashMap<>();
|
||||
String customKey = "test_key";
|
||||
String customValue = "test_value";
|
||||
conf.put(customKey, customValue);
|
||||
StreamingConfig config = new StreamingConfig(conf);
|
||||
Assert.assertEquals(config.getMap().get(customKey), customValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialization() {
|
||||
Map<String, String> conf = new HashMap<>();
|
||||
String customKey = "test_key";
|
||||
String customValue = "test_value";
|
||||
conf.put(customKey, customValue);
|
||||
StreamingConfig config = new StreamingConfig(conf);
|
||||
|
||||
FSTConfiguration fstConf = FSTConfiguration.createDefaultConfiguration();
|
||||
byte[] configBytes = fstConf.asByteArray(config);
|
||||
StreamingConfig deserializedConfig = (StreamingConfig) fstConf.asObject(configBytes);
|
||||
|
||||
Assert.assertEquals(deserializedConfig.masterConfig.commonConfig.jobId(), "default-job-id");
|
||||
Assert.assertEquals(deserializedConfig.getMap().get(customKey), customValue);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -6,6 +6,7 @@ import org.ray.streaming.api.function.impl.FlatMapFunction;
|
||||
import org.ray.streaming.api.function.impl.ReduceFunction;
|
||||
import org.ray.streaming.api.function.impl.SinkFunction;
|
||||
import org.ray.streaming.api.stream.StreamSource;
|
||||
import org.ray.streaming.runtime.BaseUnitTest;
|
||||
import org.ray.streaming.util.Config;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@@ -18,8 +19,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
||||
public class WordCountTest implements Serializable {
|
||||
public class WordCountTest extends BaseUnitTest implements Serializable {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(WordCountTest.class);
|
||||
|
||||
|
||||
+2
-1
@@ -13,6 +13,7 @@ import org.ray.streaming.api.partition.impl.RoundRobinPartition;
|
||||
import org.ray.streaming.api.stream.DataStream;
|
||||
import org.ray.streaming.api.stream.StreamSink;
|
||||
import org.ray.streaming.api.stream.StreamSource;
|
||||
import org.ray.streaming.runtime.BaseUnitTest;
|
||||
import org.ray.streaming.runtime.core.graph.ExecutionEdge;
|
||||
import org.ray.streaming.runtime.core.graph.ExecutionGraph;
|
||||
import org.ray.streaming.runtime.core.graph.ExecutionNode;
|
||||
@@ -25,7 +26,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class TaskAssignerImplTest {
|
||||
public class TaskAssignerImplTest extends BaseUnitTest {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TaskAssignerImplTest.class);
|
||||
|
||||
|
||||
+3
-1
@@ -21,6 +21,7 @@ import org.ray.streaming.api.context.StreamingContext;
|
||||
import org.ray.streaming.api.function.impl.FlatMapFunction;
|
||||
import org.ray.streaming.api.function.impl.ReduceFunction;
|
||||
import org.ray.streaming.api.stream.StreamSource;
|
||||
import org.ray.streaming.runtime.BaseUnitTest;
|
||||
import org.ray.streaming.runtime.transfer.ChannelID;
|
||||
import org.ray.streaming.runtime.util.EnvUtil;
|
||||
import org.ray.streaming.util.Config;
|
||||
@@ -32,7 +33,8 @@ import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class StreamingQueueTest implements Serializable {
|
||||
public class StreamingQueueTest extends BaseUnitTest implements Serializable {
|
||||
|
||||
private static Logger LOGGER = LoggerFactory.getLogger(StreamingQueueTest.class);
|
||||
|
||||
static {
|
||||
|
||||
+2
-2
@@ -2,11 +2,11 @@ package org.ray.streaming.runtime.transfer;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
|
||||
import org.ray.streaming.runtime.BaseUnitTest;
|
||||
import org.ray.streaming.runtime.util.EnvUtil;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class ChannelIDTest {
|
||||
public class ChannelIDTest extends BaseUnitTest {
|
||||
|
||||
static {
|
||||
EnvUtil.loadNativeLibraries();
|
||||
|
||||
Reference in New Issue
Block a user