tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ok...@apache.org
Subject tinkerpop git commit: added GraphActorsHelper which will configure a GraphActors via its fluent interface via a provided Configuration. Added a new GraphActorsTest that ensures worker counts are correct.
Date Fri, 16 Dec 2016 22:41:53 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1564 9e4dd0f85 -> e860500eb


added GraphActorsHelper which will configure a GraphActors via its fluent interface via a
provided Configuration. Added a new GraphActorsTest that ensures worker counts are correct.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/e860500e
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/e860500e
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/e860500e

Branch: refs/heads/TINKERPOP-1564
Commit: e860500eb90876ba38a49926533fe75ef9cdd427
Parents: 9e4dd0f
Author: Marko A. Rodriguez <okrammarko@gmail.com>
Authored: Fri Dec 16 15:41:47 2016 -0700
Committer: Marko A. Rodriguez <okrammarko@gmail.com>
Committed: Fri Dec 16 15:41:47 2016 -0700

----------------------------------------------------------------------
 .../akka/process/actor/AkkaGraphActors.java     | 13 +++++-
 .../gremlin/process/actor/GraphActors.java      |  2 +
 .../process/actor/util/GraphActorsHelper.java   | 48 ++++++++++++++++++++
 .../gremlin/process/actors/GraphActorsTest.java | 11 +++++
 .../process/computer/TinkerGraphComputer.java   |  5 +-
 5 files changed, 75 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e860500e/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actor/AkkaGraphActors.java
----------------------------------------------------------------------
diff --git a/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actor/AkkaGraphActors.java
b/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actor/AkkaGraphActors.java
index 05e63be..c5a77db 100644
--- a/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actor/AkkaGraphActors.java
+++ b/akka-gremlin/src/main/java/org/apache/tinkerpop/gremlin/akka/process/actor/AkkaGraphActors.java
@@ -26,11 +26,13 @@ import com.typesafe.config.ConfigFactory;
 import com.typesafe.config.ConfigValueFactory;
 import org.apache.commons.configuration.BaseConfiguration;
 import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationUtils;
 import org.apache.tinkerpop.gremlin.process.actor.ActorProgram;
 import org.apache.tinkerpop.gremlin.process.actor.ActorsResult;
 import org.apache.tinkerpop.gremlin.process.actor.Address;
 import org.apache.tinkerpop.gremlin.process.actor.GraphActors;
 import org.apache.tinkerpop.gremlin.process.actor.util.DefaultActorsResult;
+import org.apache.tinkerpop.gremlin.process.actor.util.GraphActorsHelper;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Partitioner;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
@@ -55,9 +57,10 @@ public final class AkkaGraphActors<R> implements GraphActors<R>
{
     private boolean executed = false;
 
     private AkkaGraphActors(final Configuration configuration) {
-        this.configuration = configuration;
+        this.configuration = new BaseConfiguration();
+        ConfigurationUtils.copy(configuration, this.configuration);
         this.configuration.setProperty(GRAPH_ACTORS, AkkaGraphActors.class.getCanonicalName());
-        this.workers = this.configuration.getInt(GRAPH_ACTORS_WORKERS, 1);
+        GraphActorsHelper.configure(this, this.configuration);
     }
 
     @Override
@@ -79,6 +82,12 @@ public final class AkkaGraphActors<R> implements GraphActors<R>
{
     }
 
     @Override
+    public GraphActors<R> configure(final String key, final Object value) {
+        this.configuration.addProperty(key, value);
+        return this;
+    }
+
+    @Override
     public Future<R> submit(final Graph graph) {
         if (this.executed)
             throw new IllegalStateException("Can not execute twice");

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e860500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actor/GraphActors.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actor/GraphActors.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actor/GraphActors.java
index 63804ab..29c032b 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actor/GraphActors.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actor/GraphActors.java
@@ -56,6 +56,8 @@ public interface GraphActors<R> extends Processor {
      */
     public GraphActors<R> workers(final int workers);
 
+    public GraphActors<R> configure(final String key, final Object value);
+
     /**
      * Submit the {@link ActorProgram} for execution by the {@link GraphActors}.
      *

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e860500e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actor/util/GraphActorsHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actor/util/GraphActorsHelper.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actor/util/GraphActorsHelper.java
new file mode 100644
index 0000000..eebee17
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/actor/util/GraphActorsHelper.java
@@ -0,0 +1,48 @@
+/*
+ *  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.tinkerpop.gremlin.process.actor.util;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.tinkerpop.gremlin.process.actor.GraphActors;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+
+import java.util.Iterator;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class GraphActorsHelper {
+
+    private GraphActorsHelper() {
+
+    }
+
+    public static GraphActors configure(GraphActors actors, final Configuration configuration)
{
+        final Iterator<String> keys = IteratorUtils.asList(configuration.getKeys()).iterator();
+        while (keys.hasNext()) {
+            final String key = keys.next();
+            if (key.equals(GraphActors.GRAPH_ACTORS_WORKERS))
+                actors = actors.workers(configuration.getInt(GraphActors.GRAPH_ACTORS_WORKERS));
+            else if (!key.equals(GraphActors.GRAPH_ACTORS))
+                actors = actors.configure(key, configuration.getProperty(key));
+        }
+        return actors;
+    }
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e860500e/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/actors/GraphActorsTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/actors/GraphActorsTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/actors/GraphActorsTest.java
index d040f49..ec3ece2 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/actors/GraphActorsTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/actors/GraphActorsTest.java
@@ -39,4 +39,15 @@ public class GraphActorsTest extends AbstractGremlinProcessTest {
         final GraphActors actors = graphProvider.getGraphActors(graph);
         assertEquals(StringFactory.graphActorsString(actors), actors.toString());
     }
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void shouldHaveProperWorkerCounte() {
+        final GraphActors actors = graphProvider.getGraphActors(graph);
+        for (int i = 1; i < 10; i++) {
+            assertEquals(6L, g.withProcessor(actors.workers(i)).V().count().next().longValue());
+            assertEquals(i, actors.configuration().getProperty(GraphActors.GRAPH_ACTORS_WORKERS));
+
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e860500e/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerGraphComputer.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerGraphComputer.java
b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerGraphComputer.java
index ec79ea2..f2d2527 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerGraphComputer.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerGraphComputer.java
@@ -95,9 +95,10 @@ public final class TinkerGraphComputer implements GraphComputer {
 
     private TinkerGraphComputer(final Configuration configuration) {
         this.graph = null;
-        this.configuration = configuration;
+        this.configuration = new BaseConfiguration();
+        ConfigurationUtils.copy(configuration,this.configuration);
         this.configuration.setProperty(GRAPH_COMPUTER, TinkerGraphComputer.class.getCanonicalName());
-        GraphComputerHelper.configure(this, ConfigurationUtils.cloneConfiguration(configuration));
+        GraphComputerHelper.configure(this, configuration);
     }
 
     public static TinkerGraphComputer open(final Configuration configuration) {


Mime
View raw message