|
@@ -46,13 +46,7 @@ import org.apache.livy.LivyClient;
|
|
|
import org.apache.livy.LivyClientBuilder;
|
|
|
import org.apache.livy.client.common.Serializer;
|
|
|
import org.apache.livy.rsc.rpc.RpcException;
|
|
|
-import org.apache.livy.test.jobs.Echo;
|
|
|
-import org.apache.livy.test.jobs.Failure;
|
|
|
-import org.apache.livy.test.jobs.FileReader;
|
|
|
-import org.apache.livy.test.jobs.GetCurrentUser;
|
|
|
-import org.apache.livy.test.jobs.SQLGetTweets;
|
|
|
-import org.apache.livy.test.jobs.Sleeper;
|
|
|
-import org.apache.livy.test.jobs.SmallCount;
|
|
|
+import org.apache.livy.test.jobs.*;
|
|
|
import static org.apache.livy.rsc.RSCConf.Entry.*;
|
|
|
|
|
|
public class TestSparkClient {
|
|
@@ -79,6 +73,7 @@ public class TestSparkClient {
|
|
|
conf.put(LIVY_JARS.key(), "");
|
|
|
conf.put("spark.repl.enableHiveContext", "true");
|
|
|
conf.put("spark.sql.catalogImplementation", "hive");
|
|
|
+ conf.put(RETAINED_SHARE_VARIABLES.key(), "2");
|
|
|
return conf;
|
|
|
}
|
|
|
|
|
@@ -114,6 +109,61 @@ public class TestSparkClient {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testSharedVariable() throws Exception {
|
|
|
+ runTest(true, new TestFunction() {
|
|
|
+ @Override
|
|
|
+ void call(LivyClient client) throws Exception {
|
|
|
+ for (int i = 0; i < 2; i ++) {
|
|
|
+ JobHandle<Integer> handler = client.submit(new SharedVariableCounter("test"));
|
|
|
+ assertEquals(Integer.valueOf(i), handler.get(TIMEOUT, TimeUnit.SECONDS));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private static class SharedVariableTest implements Job<Void> {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Void call(JobContext jc) throws Exception {
|
|
|
+ jc.setSharedObject("1", 1);
|
|
|
+ jc.setSharedObject("2", 2);
|
|
|
+
|
|
|
+ Integer obj = jc.getSharedObject("1");
|
|
|
+ assertEquals(obj, Integer.valueOf(1));
|
|
|
+
|
|
|
+ jc.setSharedObject("3", 3);
|
|
|
+
|
|
|
+ Exception e = null;
|
|
|
+ try {
|
|
|
+ jc.getSharedObject("2");
|
|
|
+ } catch (NoSuchElementException exp) {
|
|
|
+ e = exp;
|
|
|
+ }
|
|
|
+
|
|
|
+ assertNotNull(e);
|
|
|
+
|
|
|
+ obj = jc.removeSharedObject("2");
|
|
|
+ assertNull(obj);
|
|
|
+
|
|
|
+ obj = jc.removeSharedObject("3");
|
|
|
+ assertEquals(obj, Integer.valueOf(3));
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testRemoveSharedVariableWithLRU() throws Exception {
|
|
|
+ runTest(true, new TestFunction() {
|
|
|
+ @Override
|
|
|
+ void call(LivyClient client) throws Exception {
|
|
|
+ JobHandle<Void> handler = client.submit(new SharedVariableTest());
|
|
|
+ handler.get(TIMEOUT, TimeUnit.SECONDS);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testJobFailure() throws Exception {
|
|
|
runTest(true, new TestFunction() {
|