incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [4/6] Massive change to arguments in the new command platform. Now arguments are passed by annotating fields on the commands themselves. So therefore the Args object was removed.
Date Wed, 01 Oct 2014 01:49:47 GMT
http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java b/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
index c438fa8..c323d4e 100644
--- a/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
+++ b/blur-core/src/main/java/org/apache/blur/thrift/BlurShardServer.java
@@ -31,6 +31,8 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLongArray;
 
+import org.apache.blur.command.ArgumentOverlay;
+import org.apache.blur.command.BlurObject;
 import org.apache.blur.command.CommandUtil;
 import org.apache.blur.command.ExecutionId;
 import org.apache.blur.command.Response;
@@ -607,7 +609,8 @@ public class BlurShardServer extends TableAdmin implements Iface {
               table));
         }
       };
-      Response response = _commandManager.execute(tableContextFactory, commandName, CommandUtil.toArgs(arguments));
+      BlurObject args = CommandUtil.toBlurObject(arguments);
+      Response response = _commandManager.execute(tableContextFactory, commandName, new ArgumentOverlay(args));
       return CommandUtil.fromObjectToThrift(response);
     } catch (Exception e) {
       if (e instanceof org.apache.blur.command.TimeoutException) {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-core/src/test/java/org/apache/blur/command/ShardCommandManagerTest.java
----------------------------------------------------------------------
diff --git a/blur-core/src/test/java/org/apache/blur/command/ShardCommandManagerTest.java
b/blur-core/src/test/java/org/apache/blur/command/ShardCommandManagerTest.java
index 6047bfa..8ca946e 100644
--- a/blur-core/src/test/java/org/apache/blur/command/ShardCommandManagerTest.java
+++ b/blur-core/src/test/java/org/apache/blur/command/ShardCommandManagerTest.java
@@ -29,6 +29,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.SortedSet;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.blur.manager.IndexServer;
@@ -127,9 +128,10 @@ public class ShardCommandManagerTest {
     ShardCommandManager manager = new ShardCommandManager(getIndexServer(), _tmpPath, _commandPath,
10, 10, 1000,
         _config);
     {
-      Args args = new Args();
-      args.set("table", "test");
-      Response response = manager.execute(getTableContextFactory(), "test", args);
+      BlurObject args = new BlurObject();
+      args.put("table", "test");
+      ArgumentOverlay argumentOverlay = new ArgumentOverlay(args);
+      Response response = manager.execute(getTableContextFactory(), "test", argumentOverlay);
       Map<Shard, Object> shardResults = response.getShardResults();
       for (Object o : shardResults.values()) {
         assertEquals("test1", o);
@@ -148,9 +150,10 @@ public class ShardCommandManagerTest {
     assertEquals(1, manager.commandRefresh());
 
     {
-      Args args = new Args();
-      args.set("table", "test");
-      Response response = manager.execute(getTableContextFactory(), "test", args);
+      BlurObject args = new BlurObject();
+      args.put("table", "test");
+      ArgumentOverlay argumentOverlay = new ArgumentOverlay(args);
+      Response response = manager.execute(getTableContextFactory(), "test", argumentOverlay);
       Map<Shard, Object> shardResults = response.getShardResults();
       for (Object o : shardResults.values()) {
         assertEquals("test2", o);
@@ -178,15 +181,21 @@ public class ShardCommandManagerTest {
     Response response;
     ExecutionId executionId = null;
 
-    Args args = new Args();
-    args.set("seconds", 5);
-    args.set("table", "test");
+    BlurObject args = new BlurObject();
+    args.put("table", "test");
+    args.put("seconds", 5);
 
+    ArgumentOverlay argumentOverlay = new ArgumentOverlay(args);
+
+    long start = System.nanoTime();
     while (true) {
+      if (System.nanoTime() - start >= TimeUnit.SECONDS.toNanos(7)) {
+        fail();
+      }
       try {
         if (executionId == null) {
           TableContextFactory tableContextFactory = getTableContextFactory();
-          response = _manager.execute(tableContextFactory, "wait", args);
+          response = _manager.execute(tableContextFactory, "wait", argumentOverlay);
         } else {
           response = _manager.reconnect(executionId);
         }
@@ -200,12 +209,13 @@ public class ShardCommandManagerTest {
 
   @Test
   public void testShardCommandManagerErrorWait() throws IOException, TimeoutException, ExceptionCollector
{
-    Args args = new Args();
-    args.set("seconds", 1);
-    args.set("table", "test");
+    BlurObject args = new BlurObject();
+    args.put("table", "test");
+    args.put("seconds", 1);
+    ArgumentOverlay argumentOverlay = new ArgumentOverlay(args);
     TableContextFactory tableContextFactory = getTableContextFactory();
     try {
-      _manager.execute(tableContextFactory, "error", args);
+      _manager.execute(tableContextFactory, "error", argumentOverlay);
       fail();
     } catch (ExceptionCollector e) {
       Throwable t = e.getCause();
@@ -219,13 +229,15 @@ public class ShardCommandManagerTest {
     Response response;
     ExecutionId executionId = null;
 
-    Args args = new Args();
-    args.set("seconds", 5);
-    args.set("table", "test");
+    BlurObject args = new BlurObject();
+    args.put("table", "test");
+    args.put("seconds", 5);
+
+    ArgumentOverlay argumentOverlay = new ArgumentOverlay(args);
 
     try {
       TableContextFactory tableContextFactory = getTableContextFactory();
-      response = _manager.execute(tableContextFactory, "wait", args);
+      response = _manager.execute(tableContextFactory, "wait", argumentOverlay);
     } catch (TimeoutException te) {
       _manager.cancel(te.getExecutionId());
       // some how validate the threads have cancelled.

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-core/src/test/java/org/apache/blur/command/ThrowException.java
----------------------------------------------------------------------
diff --git a/blur-core/src/test/java/org/apache/blur/command/ThrowException.java b/blur-core/src/test/java/org/apache/blur/command/ThrowException.java
index 06aa3cb..cfa1804 100644
--- a/blur-core/src/test/java/org/apache/blur/command/ThrowException.java
+++ b/blur-core/src/test/java/org/apache/blur/command/ThrowException.java
@@ -18,17 +18,9 @@ package org.apache.blur.command;
 
 import java.io.IOException;
 
-import org.apache.blur.command.annotation.Argument;
-import org.apache.blur.command.annotation.OptionalArguments;
-import org.apache.blur.command.annotation.RequiredArguments;
+import org.apache.blur.command.commandtype.IndexReadCommandSingleTable;
 
-@RequiredArguments({ @Argument(name = "table", value = "The name of the table to execute
the wait for N number of seconds command.", type = String.class) })
-@OptionalArguments({
-
-@Argument(name = "shard", value = "The shard id to execute the wait for N number of seconds
command.", type = String.class),
-
-})
-public class ThrowException extends IndexReadCommand<Boolean> {
+public class ThrowException extends IndexReadCommandSingleTable<Boolean> {
 
   @Override
   public Boolean execute(IndexContext context) throws IOException, InterruptedException {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-core/src/test/java/org/apache/blur/command/WaitForSeconds.java
----------------------------------------------------------------------
diff --git a/blur-core/src/test/java/org/apache/blur/command/WaitForSeconds.java b/blur-core/src/test/java/org/apache/blur/command/WaitForSeconds.java
index 8cf6bf2..3216d7f 100644
--- a/blur-core/src/test/java/org/apache/blur/command/WaitForSeconds.java
+++ b/blur-core/src/test/java/org/apache/blur/command/WaitForSeconds.java
@@ -19,16 +19,16 @@ package org.apache.blur.command;
 import java.io.IOException;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.blur.command.annotation.Argument;
-import org.apache.blur.command.annotation.OptionalArguments;
+import org.apache.blur.command.annotation.OptionalArgument;
+import org.apache.blur.command.commandtype.IndexReadCommandSingleTable;
 
-@OptionalArguments({ @Argument(name = "seconds", value = "The number of seconds to sleep,
the default is 30 seconds.", type = Integer.class) })
-public class WaitForSeconds extends IndexReadCommand<Boolean> {
+public class WaitForSeconds extends IndexReadCommandSingleTable<Boolean> {
+
+  @OptionalArgument("The number of seconds to sleep, the default is 30 seconds.")
+  private int seconds = 30;
 
   @Override
   public Boolean execute(IndexContext context) throws IOException, InterruptedException {
-    Args args = context.getArgs();
-    int seconds = args.get("seconds", 30);
     Thread.sleep(TimeUnit.SECONDS.toMillis(seconds));
     return true;
   }
@@ -38,4 +38,12 @@ public class WaitForSeconds extends IndexReadCommand<Boolean> {
     return "wait";
   }
 
+  public int getSeconds() {
+    return seconds;
+  }
+
+  public void setSeconds(int seconds) {
+    this.seconds = seconds;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-core/src/test/resources/org/apache/blur/command/test1/TestCommand.java
----------------------------------------------------------------------
diff --git a/blur-core/src/test/resources/org/apache/blur/command/test1/TestCommand.java b/blur-core/src/test/resources/org/apache/blur/command/test1/TestCommand.java
index 349f508..c45da90 100644
--- a/blur-core/src/test/resources/org/apache/blur/command/test1/TestCommand.java
+++ b/blur-core/src/test/resources/org/apache/blur/command/test1/TestCommand.java
@@ -19,10 +19,10 @@ import java.io.IOException;
 
 import org.apache.blur.command.Command;
 import org.apache.blur.command.IndexContext;
-import org.apache.blur.command.IndexReadCommand;
+import org.apache.blur.command.commandtype.IndexReadCommandSingleTable;
 
 @SuppressWarnings("serial")
-public class TestCommand extends IndexReadCommand<String> {
+public class TestCommand extends IndexReadCommandSingleTable<String> {
 
   @Override
   public String getName() {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-core/src/test/resources/org/apache/blur/command/test1/test1.jar
----------------------------------------------------------------------
diff --git a/blur-core/src/test/resources/org/apache/blur/command/test1/test1.jar b/blur-core/src/test/resources/org/apache/blur/command/test1/test1.jar
index fb71b76..bf3cb7f 100644
Binary files a/blur-core/src/test/resources/org/apache/blur/command/test1/test1.jar and b/blur-core/src/test/resources/org/apache/blur/command/test1/test1.jar
differ

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-core/src/test/resources/org/apache/blur/command/test2/TestCommand.java
----------------------------------------------------------------------
diff --git a/blur-core/src/test/resources/org/apache/blur/command/test2/TestCommand.java b/blur-core/src/test/resources/org/apache/blur/command/test2/TestCommand.java
index 12e486e..b0902ba 100644
--- a/blur-core/src/test/resources/org/apache/blur/command/test2/TestCommand.java
+++ b/blur-core/src/test/resources/org/apache/blur/command/test2/TestCommand.java
@@ -19,10 +19,10 @@ import java.io.IOException;
 
 import org.apache.blur.command.Command;
 import org.apache.blur.command.IndexContext;
-import org.apache.blur.command.IndexReadCommand;
+import org.apache.blur.command.commandtype.IndexReadCommandSingleTable;
 
 @SuppressWarnings("serial")
-public class TestCommand extends IndexReadCommand<String> {
+public class TestCommand extends IndexReadCommandSingleTable<String> {
 
   @Override
   public String getName() {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/27107abf/blur-core/src/test/resources/org/apache/blur/command/test2/test2.jar
----------------------------------------------------------------------
diff --git a/blur-core/src/test/resources/org/apache/blur/command/test2/test2.jar b/blur-core/src/test/resources/org/apache/blur/command/test2/test2.jar
index 47dca03..daecf41 100644
Binary files a/blur-core/src/test/resources/org/apache/blur/command/test2/test2.jar and b/blur-core/src/test/resources/org/apache/blur/command/test2/test2.jar
differ


Mime
View raw message