You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/07/31 19:20:52 UTC
[01/10] incubator-tinkerpop git commit: Add a way to generate
IoRegistry instance in GryoPool from static instance.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/master 792103d1e -> acbe9b116
Add a way to generate IoRegistry instance in GryoPool from static instance.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/46e51442
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/46e51442
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/46e51442
Branch: refs/heads/master
Commit: 46e51442873f994159614995dbb0ffaefb91b416
Parents: bcdd45b
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Jul 28 07:53:07 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Jul 28 07:53:07 2015 -0400
----------------------------------------------------------------------
.../gremlin/structure/io/IoRegistry.java | 5 ++--
.../gremlin/structure/io/gryo/GryoPool.java | 14 +++++++---
.../gremlin/structure/io/gryo/GryoPoolTest.java | 28 +++++++++++++++++---
3 files changed, 38 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/46e51442/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoRegistry.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoRegistry.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoRegistry.java
index fee2811..e73b01e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoRegistry.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/IoRegistry.java
@@ -35,8 +35,9 @@ import java.util.stream.Collectors;
* A generalized custom serializer registry for vendors implementing a {@link Graph}. Vendors should provide an
* implementation of this interface if their implementation requires custom serialization of identifiers or other
* such content housed in their graph. Consider extending from {@link AbstractIoRegistry} and ensure that the
- * implementation has a zero-arg constructor, as implementations may need to be constructed from reflection
- * given different parts of the TinkerPop stack.
+ * implementation has a zero-arg constructor or a static "getInstance" method that returns an {@code IoRegistry}
+ * instance, as implementations may need to be constructed from reflection given different parts of the TinkerPop
+ * stack.
* <p/>
* The serializers to register depend on the {@link Io} implementations that are expected to be supported. There
* are currently two core implementations in {@link GryoIo} and {@link GraphSONIo}. Both of these should be supported
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/46e51442/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
index 2641e56..d27694e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
@@ -20,8 +20,8 @@ package org.apache.tinkerpop.gremlin.structure.io.gryo;
import org.apache.commons.configuration.Configuration;
import org.apache.tinkerpop.gremlin.structure.io.IoRegistry;
-import org.apache.tinkerpop.gremlin.structure.io.Mapper;
+import java.lang.reflect.Method;
import java.util.Optional;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
@@ -127,8 +127,16 @@ public final class GryoPool {
if (className.isEmpty()) return Optional.empty();
try {
- final Class clazz = Class.forName(className);
- return Optional.of((IoRegistry) clazz.newInstance());
+ final Class<?> clazz = Class.forName(className);
+ try {
+ final Method instanceMethod = clazz.getDeclaredMethod("getInstance");
+ if (IoRegistry.class.isAssignableFrom(instanceMethod.getReturnType()))
+ return Optional.of((IoRegistry) instanceMethod.invoke(null));
+ else
+ throw new Exception();
+ } catch (Exception methodex) {
+ return Optional.of((IoRegistry) clazz.newInstance());
+ }
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/46e51442/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPoolTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPoolTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPoolTest.java
index ddc1aeb..8a033c6 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPoolTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPoolTest.java
@@ -81,9 +81,17 @@ public class GryoPoolTest {
}
@Test
- public void shouldConfigPoolOnConstructionWithCustomIoRegistry() throws Exception {
+ public void shouldConfigPoolOnConstructionWithCustomIoRegistryConstructor() throws Exception {
final Configuration conf = new BaseConfiguration();
- conf.setProperty(GryoPool.CONFIG_IO_REGISTRY, CustomIoRegistry.class.getName());
+ conf.setProperty(GryoPool.CONFIG_IO_REGISTRY, CustomIoRegistryConstructorBased.class.getName());
+ final GryoPool pool = new GryoPool(conf);
+ assertReaderWriter(pool.takeWriter(), pool.takeReader(), new Junk("test"), Junk.class);
+ }
+
+ @Test
+ public void shouldConfigPoolOnConstructionWithCustomIoRegistryInstance() throws Exception {
+ final Configuration conf = new BaseConfiguration();
+ conf.setProperty(GryoPool.CONFIG_IO_REGISTRY, CustomIoRegistryInstanceBased.class.getName());
final GryoPool pool = new GryoPool(conf);
assertReaderWriter(pool.takeWriter(), pool.takeReader(), new Junk("test"), Junk.class);
}
@@ -139,9 +147,21 @@ public class GryoPoolTest {
}
}
- public static class CustomIoRegistry extends AbstractIoRegistry {
- public CustomIoRegistry() {
+ public static class CustomIoRegistryConstructorBased extends AbstractIoRegistry {
+ public CustomIoRegistryConstructorBased() {
register(GryoIo.class, Junk.class, null);
}
}
+
+ public static class CustomIoRegistryInstanceBased extends AbstractIoRegistry {
+ private static CustomIoRegistryInstanceBased INSTANCE = new CustomIoRegistryInstanceBased();
+
+ private CustomIoRegistryInstanceBased() {
+ register(GryoIo.class, Junk.class, null);
+ }
+
+ public static CustomIoRegistryInstanceBased getInstance() {
+ return INSTANCE;
+ }
+ }
}
[04/10] incubator-tinkerpop git commit: Fix link to Ogre.
Posted by sp...@apache.org.
Fix link to Ogre.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/d384111f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/d384111f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/d384111f
Branch: refs/heads/master
Commit: d384111fc1f15432a1b50977c7f981303dcd4aac
Parents: d33fb15
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jul 30 12:34:14 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Jul 30 12:34:14 2015 -0400
----------------------------------------------------------------------
docs/src/intro.asciidoc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d384111f/docs/src/intro.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/intro.asciidoc b/docs/src/intro.asciidoc
index a7bc4c4..d3fa961 100644
--- a/docs/src/intro.asciidoc
+++ b/docs/src/intro.asciidoc
@@ -263,7 +263,7 @@ CAUTION: A Traversal's result are never ordered unless explicitly by means of <<
On Gremlin Language Variants
----------------------------
-Gremlin is written in Java8. There are various language variants of Gremlin such as Gremlin-Groovy (packaged with TinkerPop3), link:https://github.com/mpollmeier/gremlin-scala[Gremlin-Scala], Gremlin-JavaScript, Gremlin-Clojure (known as link:link:https://github.com/clojurewerkz/ogre[Ogre]), etc. It is best to think of Gremlin as a style of graph traversing that is not bound to a particular programming language per se. Within a programming language familiar to the developer, there is a Gremlin variant that they can use that leverages the idioms of that language. At minimum, a programming language providing a Gremlin implementation must support link:http://en.wikipedia.org/wiki/Method_chaining[function chaining] (with link:http://en.wikipedia.org/wiki/Anonymous_function[lambdas/anonymous functions] being a "nice to have" if the variants wishes to offer arbitrary computations beyond the provided Gremlin steps).
+Gremlin is written in Java8. There are various language variants of Gremlin such as Gremlin-Groovy (packaged with TinkerPop3), link:https://github.com/mpollmeier/gremlin-scala[Gremlin-Scala], Gremlin-JavaScript, Gremlin-Clojure (known as link:https://github.com/clojurewerkz/ogre[Ogre]), etc. It is best to think of Gremlin as a style of graph traversing that is not bound to a particular programming language per se. Within a programming language familiar to the developer, there is a Gremlin variant that they can use that leverages the idioms of that language. At minimum, a programming language providing a Gremlin implementation must support link:http://en.wikipedia.org/wiki/Method_chaining[function chaining] (with link:http://en.wikipedia.org/wiki/Anonymous_function[lambdas/anonymous functions] being a "nice to have" if the variants wishes to offer arbitrary computations beyond the provided Gremlin steps).
Throughout the documentation, the examples provided are primarily written in Gremlin-Groovy. The reason for this is the <<gremlin-console,Gremlin Console>> whereby an interactive programming environment exists that does not require code compilation. For learning TinkerPop3 and interacting with a live graph system in an ad hoc manner, the Gremlin Console is invaluable. However, for developers interested in working with Gremlin-Java, a few Groovy-to-Java patterns are presented below.
[05/10] incubator-tinkerpop git commit: Update javadocs around
transactions and Graph.close()
Posted by sp...@apache.org.
Update javadocs around transactions and Graph.close()
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/58b699e6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/58b699e6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/58b699e6
Branch: refs/heads/master
Commit: 58b699e6b636eb40a6868725c85a245996798fbd
Parents: d384111
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Jul 30 16:58:43 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Jul 30 16:58:43 2015 -0400
----------------------------------------------------------------------
.../tinkerpop/gremlin/structure/Graph.java | 14 ++++++++-
.../gremlin/structure/Transaction.java | 30 ++++++++++----------
2 files changed, 28 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/58b699e6/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
index 99b82dd..d4c15d8 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
@@ -239,11 +239,23 @@ public interface Graph extends AutoCloseable, Host {
public Iterator<Edge> edges(final Object... edgeIds);
/**
- * Configure and control the transactions for those graphs that support this feature.
+ * Configure and control the transactions for those graphs that support this feature. Note that this method does
+ * not indicate the creation of a "transaction" object. A {@link Transaction} in the TinkerPop context is a
+ * transaction "factory" or "controller" that helps manage transactions owned by the underlying graph database.
*/
public Transaction tx();
/**
+ * Closing a {@code Graph} is equivalent to "shutdown". Users should consult the documentation of the underlying
+ * graph database implementation for what this "shutdown" will mean as it pertains to open transactions. It will
+ * typically be the end user's responsibility to synchronize the thread that calls {@code close()} with other
+ * threads that are accessing open transactions. In other words, be sure that all work performed on the
+ * {@code Graph} instance is complete prior to calling this method.
+ */
+ @Override
+ void close() throws Exception;
+
+ /**
* Construct a particular {@link Io} implementation for reading and writing the {@code Graph} and other data.
* End-users will "select" the {@link Io} implementation that they want to use by supplying the {@link Io.Builder}
* that constructs it. In this way, {@code Graph} vendors can supply their {@link IoRegistry} to that builder
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/58b699e6/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java
index e97a914..d80c87f 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java
@@ -18,6 +18,8 @@
*/
package org.apache.tinkerpop.gremlin.structure;
+import org.apache.tinkerpop.gremlin.structure.util.AbstractTransaction;
+
import java.io.Closeable;
import java.util.Collections;
import java.util.Set;
@@ -27,8 +29,8 @@ import java.util.function.Function;
/**
* A set of methods that allow for control of transactional behavior of a {@link Graph} instance. Vendors may
- * consider using {@link org.apache.tinkerpop.gremlin.structure.util.AbstractTransaction} as a base implementation
- * that provides default features for most of these methods.
+ * consider using {@link AbstractTransaction} as a base implementation that provides default features for most of
+ * these methods.
* <p/>
* It is expected that this interface be implemented by vendors in a {@link ThreadLocal} fashion. In other words
* transactions are bound to the current thread, which means that any graph operation executed by the thread occurs
@@ -93,9 +95,8 @@ public interface Transaction extends Closeable {
public Transaction onReadWrite(final Consumer<Transaction> consumer);
/**
- * Describes what happens to a transaction on a call to {@link org.apache.tinkerpop.gremlin.structure.Graph#close()}.
- * This value can be set using standard behavior defined in {@link CLOSE_BEHAVIOR} or a mapper {@link Consumer}
- * function.
+ * Describes what happens to a transaction on a call to {@link Graph#close()}. This value can be set using
+ * standard behavior defined in {@link CLOSE_BEHAVIOR} or a mapper {@link Consumer} function.
*/
public Transaction onClose(final Consumer<Transaction> consumer);
@@ -155,9 +156,9 @@ public interface Transaction extends Closeable {
}
/**
- * Behaviors to supply to the {@link #onClose(java.util.function.Consumer)}.
+ * Behaviors to supply to the {@link #onClose(Consumer)}.
*/
- public static enum CLOSE_BEHAVIOR implements Consumer<Transaction> {
+ public enum CLOSE_BEHAVIOR implements Consumer<Transaction> {
/**
* Any open transaction will commit on close.
*/
@@ -190,9 +191,9 @@ public interface Transaction extends Closeable {
}
/**
- * Behaviors to supply to the {@link #onReadWrite(java.util.function.Consumer)}.
+ * Behaviors to supply to the {@link #onReadWrite(Consumer)}.
*/
- public static enum READ_WRITE_BEHAVIOR implements Consumer<Transaction> {
+ public enum READ_WRITE_BEHAVIOR implements Consumer<Transaction> {
/**
* Transactions are automatically started when a read or a write occurs.
*/
@@ -215,12 +216,11 @@ public interface Transaction extends Closeable {
}
/**
- * A {@link Workload} represents a unit of work constructed by the
- * {@link Workload#submit(java.util.function.Function)} method on the {@link Transaction} interface.
- * The unit of work is a {@link java.util.function.Function} typically containing mutations to the {@link Graph}. The
- * {@link Workload} is responsible for executing the unit of work in the context of a retry strategy, such that a
- * failed unit of work is rolled back and executed again until retries are exhausted or the unit of work succeeds
- * with a commit operation.
+ * A {@link Workload} represents a unit of work constructed by the {@link Workload#submit(Function)} method on
+ * the {@link Transaction} interface. The unit of work is a {@link Function} typically containing mutations to
+ * the {@link Graph}. The {@link Workload} is responsible for executing the unit of work in the context of a
+ * retry strategy, such that a failed unit of work is rolled back and executed again until retries are exhausted
+ * or the unit of work succeeds with a commit operation.
*
* @param <R> The type of the result from the unit of work.
*/
[03/10] incubator-tinkerpop git commit: Mapper.Builder now supports
the addition of multiple IoRegistry objects.
Posted by sp...@apache.org.
Mapper.Builder now supports the addition of multiple IoRegistry objects.
This allows the user to easily add IoRegistry instances from multiple Graph implementations. This is of course useful for data migrations where each graph has its own IoRegistry.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/d33fb15f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/d33fb15f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/d33fb15f
Branch: refs/heads/master
Commit: d33fb15fd5d70e90b81edf16aba489b8eb8f7730
Parents: 31aeb13
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Jul 28 12:57:58 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Jul 28 12:57:58 2015 -0400
----------------------------------------------------------------------
docs/src/gremlin-applications.asciidoc | 3 +
.../tinkerpop/gremlin/structure/io/Mapper.java | 6 +-
.../structure/io/graphson/GraphSONIo.java | 3 +-
.../structure/io/graphson/GraphSONMapper.java | 8 +--
.../gremlin/structure/io/gryo/GryoIo.java | 2 +-
.../gremlin/structure/io/gryo/GryoMapper.java | 9 +--
.../gremlin/structure/io/gryo/GryoPool.java | 55 +++++++++------
.../tinkerpop/gremlin/structure/io/IoX.java | 50 ++++++++++++++
.../gremlin/structure/io/IoXIoRegistry.java | 44 ++++++++++++
.../tinkerpop/gremlin/structure/io/IoY.java | 52 +++++++++++++++
.../gremlin/structure/io/IoYIoRegistry.java | 44 ++++++++++++
.../structure/io/gryo/GryoMapperTest.java | 70 +++++++++++++++++++-
.../gremlin/structure/io/gryo/GryoPoolTest.java | 68 ++++++-------------
.../driver/ser/GryoMessageSerializerV1d0.java | 57 ++++++++++++----
14 files changed, 376 insertions(+), 95 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/docs/src/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/gremlin-applications.asciidoc b/docs/src/gremlin-applications.asciidoc
index e38af95..2949957 100644
--- a/docs/src/gremlin-applications.asciidoc
+++ b/docs/src/gremlin-applications.asciidoc
@@ -740,9 +740,12 @@ It has the MIME type of `application/vnd.gremlin-v1.0+gryo` and the following co
|Key |Description |Default
|serializeResultToString |When set to `true`, results are serialized by first calling `toString()` on each object in the result list resulting in an extended MIME Type of `application/vnd.gremlin-v1.0+gryo-stringd`. When set to `false` Kryo-based serialization is applied. |_false_
|useMapperFromGraph |Specifies the name of the `Graph` (from the `graphs` `Map` in the configuration file) from which to plugin any custom serializers that are tied to it. |_none_
+|ioRegistries |A list of `IoRegistry` implementations to be applied to the serializer.
|custom |A list of classes with custom kryo `Serializer` implementations related to them in the form of `<class>;<serializer-class>`. |_none_
|=========================================================
+As described above, there are multiple ways in which to register serializers for Kryo-based serialization. These configurations can be used in conjunction with one another where there is a specific ordering to how the configurations are applied. The `userMapperFromGraph` setting is applied first, followed by any `ioRegistries` and finalized by the `custom` setting.
+
Best Practices
~~~~~~~~~~~~~~
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Mapper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Mapper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Mapper.java
index 16f7a9a..4aeb3b7 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Mapper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/Mapper.java
@@ -40,7 +40,11 @@ public interface Mapper<T> {
/**
* Adds a vendor supplied {@link IoRegistry} to the {@code Mapper.Builder} which enables it to check for
* vendor custom serializers to add to the {@link Mapper}. All {@link Io} implementations should expose
- * this method via this {@link Builder} so that it is compatible with {@link Graph#io}.
+ * this method via this {@link Builder} so that it is compatible with {@link Graph#io}. Successive calls
+ * to this method will add multiple registries. Registry order must be respected when doing so. In
+ * other words, data written with {@link IoRegistry} {@code A} added first and {@code B} second must be read
+ * by a {@code Mapper} with that same registry ordering. Attempting to add {@code B} before {@code A} will
+ * result in errors.
*/
public B addRegistry(final IoRegistry registry);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONIo.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONIo.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONIo.java
index 29d14cf..f4044e1 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONIo.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONIo.java
@@ -21,6 +21,7 @@ package org.apache.tinkerpop.gremlin.structure.io.graphson;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.io.Io;
import org.apache.tinkerpop.gremlin.structure.io.IoRegistry;
+import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoMapper;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -64,7 +65,7 @@ public final class GraphSONIo implements Io<GraphSONReader.Builder, GraphSONWrit
*/
@Override
public GraphSONMapper.Builder mapper() {
- return GraphSONMapper.build().addRegistry(this.registry);
+ return (null == this.registry) ? GraphSONMapper.build() : GraphSONMapper.build().addRegistry(registry);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java
index ea1ea2b..0e5eb5b 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONMapper.java
@@ -117,7 +117,7 @@ public class GraphSONMapper implements Mapper<ObjectMapper> {
private boolean loadCustomModules = false;
private boolean normalize = false;
private boolean embedTypes = false;
- private IoRegistry registry = null;
+ private List<IoRegistry> registries = new ArrayList<>();
private GraphSONVersion version = GraphSONVersion.V1_0;
private Builder() {
@@ -128,7 +128,7 @@ public class GraphSONMapper implements Mapper<ObjectMapper> {
*/
@Override
public Builder addRegistry(final IoRegistry registry) {
- this.registry = registry;
+ registries.add(registry);
return this;
}
@@ -182,10 +182,10 @@ public class GraphSONMapper implements Mapper<ObjectMapper> {
}
public GraphSONMapper create() {
- if (registry != null) {
+ registries.forEach(registry -> {
final List<Pair<Class, SimpleModule>> simpleModules = registry.find(GraphSONIo.class, SimpleModule.class);
simpleModules.stream().map(Pair::getValue1).forEach(this.customModules::add);
- }
+ });
return new GraphSONMapper(customModules, loadCustomModules, normalize, embedTypes, version);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoIo.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoIo.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoIo.java
index bc4b6aa..aca9d74 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoIo.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoIo.java
@@ -64,7 +64,7 @@ public final class GryoIo implements Io<GryoReader.Builder, GryoWriter.Builder,
*/
@Override
public GryoMapper.Builder mapper() {
- return GryoMapper.build().addRegistry(this.registry);
+ return (null == this.registry) ? GryoMapper.build() : GryoMapper.build().addRegistry(this.registry);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
index 8d88f93..8b96052 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
@@ -248,7 +248,7 @@ public final class GryoMapper implements Mapper<Kryo> {
add(Triplet.<Class, Function<Kryo, Serializer>, Integer>with(DependantMutableMetrics.class, null, 80));
}};
- private IoRegistry registry = null;
+ private List<IoRegistry> registries = new ArrayList<>();
/**
* Starts numbering classes for Gryo serialization at 65536 to leave room for future usage by TinkerPop.
@@ -263,7 +263,8 @@ public final class GryoMapper implements Mapper<Kryo> {
*/
@Override
public Builder addRegistry(final IoRegistry registry) {
- this.registry = registry;
+ if (null == registry) throw new IllegalArgumentException("The registry cannot be null");
+ this.registries.add(registry);
return this;
}
@@ -299,7 +300,7 @@ public final class GryoMapper implements Mapper<Kryo> {
*/
public GryoMapper create() {
// consult the registry if provided and inject registry entries as custom classes.
- if (registry != null) {
+ registries.forEach(registry-> {
final List<Pair<Class, Object>> serializers = registry.find(GryoIo.class);
serializers.forEach(p -> {
if (null == p.getValue1())
@@ -315,7 +316,7 @@ public final class GryoMapper implements Mapper<Kryo> {
Serializer.class.getName(), Kryo.class.getSimpleName(),
Serializer.class.getSimpleName()));
});
- }
+ });
return new GryoMapper(serializationList);
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
index d27694e..426997e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPool.java
@@ -22,7 +22,9 @@ import org.apache.commons.configuration.Configuration;
import org.apache.tinkerpop.gremlin.structure.io.IoRegistry;
import java.lang.reflect.Method;
-import java.util.Optional;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.function.Consumer;
@@ -47,11 +49,14 @@ public final class GryoPool {
/**
* Create a pool of readers and writers from a {@code Configuration} object. There are two configuration keys
- * expected: "gremlin.io.registry" which defines a fully qualified class name of an {@link IoRegistry}
- * implementation and the "gremlin.io.gryo.poolSize" which defines the initial size of the {@code GryoPool}.
+ * expected: "gremlin.io.registry" which defines comma separated list of the fully qualified class names of
+ * {@link IoRegistry} implementations to use and the "gremlin.io.gryo.poolSize" which defines the initial size
+ * of the {@code GryoPool}. As with usage of {@link GryoMapper.Builder#addRegistry(IoRegistry)}, the order in
+ * which these items are added matters greatly. The order used for writing should be the order used for reading.
*/
public GryoPool(final Configuration conf) {
- this(conf.getInt(CONFIG_IO_GRYO_POOL_SIZE, 256), Type.READER_WRITER, tryCreateIoRegistry(conf.getString(CONFIG_IO_REGISTRY, "")));
+ this(conf.getInt(CONFIG_IO_GRYO_POOL_SIZE, 256), Type.READER_WRITER,
+ tryCreateIoRegistry(conf.getList(CONFIG_IO_REGISTRY, Collections.emptyList())));
}
/**
@@ -61,7 +66,7 @@ public final class GryoPool {
* @param poolSize initial size of the pool.
*/
public GryoPool(final int poolSize) {
- this(poolSize, Type.READER_WRITER, Optional.empty());
+ this(poolSize, Type.READER_WRITER, Collections.emptyList());
}
/**
@@ -70,11 +75,11 @@ public final class GryoPool {
*
* @param poolSize initial size of the pool.
* @param type the type of pool.
- * @param ioRegistry the registry to assign to each {@link GryoReader} and {@link GryoWriter} instances.
+ * @param registries a list of registries to assign to each {@link GryoReader} and {@link GryoWriter} instances.
*/
- public GryoPool(final int poolSize, final Type type, final Optional<IoRegistry> ioRegistry) {
+ public GryoPool(final int poolSize, final Type type, final List<IoRegistry> registries) {
final GryoMapper.Builder mapperBuilder = GryoMapper.build();
- ioRegistry.ifPresent(mapperBuilder::addRegistry);
+ registries.forEach(mapperBuilder::addRegistry);
// should be able to re-use the GryoMapper - it creates fresh kryo instances from its createMapper method
mapper = mapperBuilder.create();
@@ -123,22 +128,28 @@ public final class GryoPool {
this.offerWriter(gryoWriter);
}
- private static Optional<IoRegistry> tryCreateIoRegistry(final String className) {
- if (className.isEmpty()) return Optional.empty();
+ private static List<IoRegistry> tryCreateIoRegistry(final List<Object> classNames) {
+ if (classNames.isEmpty()) return Collections.emptyList();
- try {
- final Class<?> clazz = Class.forName(className);
+ final List<IoRegistry> registries = new ArrayList<>();
+ classNames.forEach(c -> {
try {
- final Method instanceMethod = clazz.getDeclaredMethod("getInstance");
- if (IoRegistry.class.isAssignableFrom(instanceMethod.getReturnType()))
- return Optional.of((IoRegistry) instanceMethod.invoke(null));
- else
- throw new Exception();
- } catch (Exception methodex) {
- return Optional.of((IoRegistry) clazz.newInstance());
+ final String className = c.toString();
+ final Class<?> clazz = Class.forName(className);
+ try {
+ final Method instanceMethod = clazz.getDeclaredMethod("getInstance");
+ if (IoRegistry.class.isAssignableFrom(instanceMethod.getReturnType()))
+ registries.add((IoRegistry) instanceMethod.invoke(null));
+ else
+ throw new Exception();
+ } catch (Exception methodex) {
+ // tried getInstance() and that failed so try newInstance() no-arg constructor
+ registries.add((IoRegistry) clazz.newInstance());
+ }
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex);
}
- } catch (Exception ex) {
- throw new IllegalStateException(ex);
- }
+ });
+ return registries;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoX.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoX.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoX.java
new file mode 100644
index 0000000..2f67382
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoX.java
@@ -0,0 +1,50 @@
+/*
+ * 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.structure.io;
+
+/**
+ * A test class to be serialized.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class IoX {
+ private String x;
+
+ private IoX() {}
+
+ public IoX(final String x) {
+ this.x = x;
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ final IoX ioX = (IoX) o;
+
+ return x.equals(ioX.x);
+
+ }
+
+ @Override
+ public int hashCode() {
+ return x.hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoXIoRegistry.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoXIoRegistry.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoXIoRegistry.java
new file mode 100644
index 0000000..dabdae8
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoXIoRegistry.java
@@ -0,0 +1,44 @@
+/*
+ * 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.structure.io;
+
+import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoIo;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class IoXIoRegistry {
+ public static class ConstructorBased extends AbstractIoRegistry {
+ public ConstructorBased() {
+ register(GryoIo.class, IoX.class, null);
+ }
+ }
+
+ public static class InstanceBased extends AbstractIoRegistry {
+ private static InstanceBased INSTANCE = new InstanceBased();
+
+ private InstanceBased() {
+ register(GryoIo.class, IoX.class, null);
+ }
+
+ public static InstanceBased getInstance() {
+ return INSTANCE;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoY.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoY.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoY.java
new file mode 100644
index 0000000..ddbb221
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoY.java
@@ -0,0 +1,52 @@
+/*
+ * 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.structure.io;
+
+/**
+ * A test class to be serialized.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class IoY {
+ private Integer y;
+ private Integer z;
+
+ private IoY() {}
+
+ public IoY(final int y, final int z) {
+ this.y = y;
+ this.z = z;
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ final IoY ioY = (IoY) o;
+
+ return y.equals(ioY.y);
+
+ }
+
+ @Override
+ public int hashCode() {
+ return y.hashCode();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoYIoRegistry.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoYIoRegistry.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoYIoRegistry.java
new file mode 100644
index 0000000..1d03500
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/IoYIoRegistry.java
@@ -0,0 +1,44 @@
+/*
+ * 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.structure.io;
+
+import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoIo;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class IoYIoRegistry {
+ public static class ConstructorBased extends AbstractIoRegistry {
+ public ConstructorBased() {
+ register(GryoIo.class, IoY.class, null);
+ }
+ }
+
+ public static class InstanceBased extends AbstractIoRegistry {
+ private static InstanceBased INSTANCE = new InstanceBased();
+
+ private InstanceBased() {
+ register(GryoIo.class, IoY.class, null);
+ }
+
+ public static InstanceBased getInstance() {
+ return INSTANCE;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapperTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapperTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapperTest.java
index 21bc5bc..b500495 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapperTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapperTest.java
@@ -18,8 +18,22 @@
*/
package org.apache.tinkerpop.gremlin.structure.io.gryo;
+import org.apache.tinkerpop.gremlin.structure.io.IoX;
+import org.apache.tinkerpop.gremlin.structure.io.IoXIoRegistry;
+import org.apache.tinkerpop.gremlin.structure.io.IoY;
+import org.apache.tinkerpop.gremlin.structure.io.IoYIoRegistry;
+import org.apache.tinkerpop.shaded.kryo.Kryo;
+import org.apache.tinkerpop.shaded.kryo.io.Input;
+import org.apache.tinkerpop.shaded.kryo.io.Output;
import org.junit.Test;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotSame;
/**
@@ -27,8 +41,62 @@ import static org.junit.Assert.assertNotSame;
*/
public class GryoMapperTest {
@Test
- public void shouldGetMostRecentVersion() {
+ public void shouldMakeNewInstance() {
final GryoMapper.Builder b = GryoMapper.build();
assertNotSame(b, GryoMapper.build());
}
+
+ @Test
+ public void shouldRegisterMultipleIoRegistryToSerialize() throws Exception {
+ final GryoMapper mapper = GryoMapper.build()
+ .addRegistry(IoXIoRegistry.InstanceBased.getInstance())
+ .addRegistry(IoYIoRegistry.InstanceBased.getInstance()).create();
+ final Kryo kryo = mapper.createMapper();
+ try (final OutputStream stream = new ByteArrayOutputStream()) {
+ final Output out = new Output(stream);
+ final IoX x = new IoX("x");
+ final IoY y = new IoY(100, 200);
+ kryo.writeClassAndObject(out, x);
+ kryo.writeClassAndObject(out, y);
+
+ try (final InputStream inputStream = new ByteArrayInputStream(out.toBytes())) {
+ final Input input = new Input(inputStream);
+ final IoX readX = (IoX) kryo.readClassAndObject(input);
+ final IoY readY = (IoY) kryo.readClassAndObject(input);
+ assertEquals(x, readX);
+ assertEquals(y, readY);
+ }
+ }
+ }
+
+ @Test
+ public void shouldExpectReadFailureAsIoRegistryOrderIsNotRespected() throws Exception {
+ final GryoMapper mapperWrite = GryoMapper.build()
+ .addRegistry(IoXIoRegistry.InstanceBased.getInstance())
+ .addRegistry(IoYIoRegistry.InstanceBased.getInstance()).create();
+
+ final GryoMapper mapperRead = GryoMapper.build()
+ .addRegistry(IoYIoRegistry.InstanceBased.getInstance())
+ .addRegistry(IoXIoRegistry.InstanceBased.getInstance()).create();
+
+ final Kryo kryoWriter = mapperWrite.createMapper();
+ final Kryo kryoReader = mapperRead.createMapper();
+ try (final OutputStream stream = new ByteArrayOutputStream()) {
+ final Output out = new Output(stream);
+ final IoX x = new IoX("x");
+ final IoY y = new IoY(100, 200);
+ kryoWriter.writeClassAndObject(out, x);
+ kryoWriter.writeClassAndObject(out, y);
+
+ try (final InputStream inputStream = new ByteArrayInputStream(out.toBytes())) {
+ final Input input = new Input(inputStream);
+
+ // kryo will read a IoY instance as we've reversed the registries. it is neither an X or a Y
+ // so assert that both are incorrect
+ final IoY readY = (IoY) kryoReader.readClassAndObject(input);
+ assertNotEquals(y, readY);
+ assertNotEquals(x, readY);
+ }
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPoolTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPoolTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPoolTest.java
index 8a033c6..ea4bac7 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPoolTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoPoolTest.java
@@ -21,6 +21,10 @@ package org.apache.tinkerpop.gremlin.structure.io.gryo;
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.commons.configuration.Configuration;
import org.apache.tinkerpop.gremlin.structure.io.AbstractIoRegistry;
+import org.apache.tinkerpop.gremlin.structure.io.IoX;
+import org.apache.tinkerpop.gremlin.structure.io.IoXIoRegistry;
+import org.apache.tinkerpop.gremlin.structure.io.IoY;
+import org.apache.tinkerpop.gremlin.structure.io.IoYIoRegistry;
import org.apache.tinkerpop.gremlin.util.function.FunctionUtils;
import org.junit.Test;
@@ -83,24 +87,34 @@ public class GryoPoolTest {
@Test
public void shouldConfigPoolOnConstructionWithCustomIoRegistryConstructor() throws Exception {
final Configuration conf = new BaseConfiguration();
- conf.setProperty(GryoPool.CONFIG_IO_REGISTRY, CustomIoRegistryConstructorBased.class.getName());
+ conf.setProperty(GryoPool.CONFIG_IO_REGISTRY, IoXIoRegistry.ConstructorBased.class.getName());
final GryoPool pool = new GryoPool(conf);
- assertReaderWriter(pool.takeWriter(), pool.takeReader(), new Junk("test"), Junk.class);
+ assertReaderWriter(pool.takeWriter(), pool.takeReader(), new IoX("test"), IoX.class);
}
@Test
public void shouldConfigPoolOnConstructionWithCustomIoRegistryInstance() throws Exception {
final Configuration conf = new BaseConfiguration();
- conf.setProperty(GryoPool.CONFIG_IO_REGISTRY, CustomIoRegistryInstanceBased.class.getName());
+ conf.setProperty(GryoPool.CONFIG_IO_REGISTRY, IoXIoRegistry.InstanceBased.class.getName());
final GryoPool pool = new GryoPool(conf);
- assertReaderWriter(pool.takeWriter(), pool.takeReader(), new Junk("test"), Junk.class);
+ assertReaderWriter(pool.takeWriter(), pool.takeReader(), new IoX("test"), IoX.class);
+ }
+
+ @Test
+ public void shouldConfigPoolOnConstructionWithMultipleCustomIoRegistries() throws Exception {
+ final Configuration conf = new BaseConfiguration();
+ conf.setProperty(GryoPool.CONFIG_IO_REGISTRY,
+ IoXIoRegistry.InstanceBased.class.getName() + "," + IoYIoRegistry.InstanceBased.class.getName());
+ final GryoPool pool = new GryoPool(conf);
+ assertReaderWriter(pool.takeWriter(), pool.takeReader(), new IoX("test"), IoX.class);
+ assertReaderWriter(pool.takeWriter(), pool.takeReader(), new IoY(100, 200), IoY.class);
}
@Test(expected = IllegalArgumentException.class)
public void shouldConfigPoolOnConstructionWithoutCustomIoRegistryAndFail() throws Exception {
final Configuration conf = new BaseConfiguration();
final GryoPool pool = new GryoPool(conf);
- assertReaderWriter(pool.takeWriter(), pool.takeReader(), new Junk("test"), Junk.class);
+ assertReaderWriter(pool.takeWriter(), pool.takeReader(), new IoX("test"), IoX.class);
}
@Test(expected = IllegalStateException.class)
@@ -120,48 +134,4 @@ public class GryoPoolTest {
}
}
}
-
- public static class Junk {
- private String x;
-
- private Junk() {}
-
- public Junk(final String x) {
- this.x = x;
- }
-
- @Override
- public boolean equals(final Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- final Junk junk = (Junk) o;
-
- return x.equals(junk.x);
-
- }
-
- @Override
- public int hashCode() {
- return x.hashCode();
- }
- }
-
- public static class CustomIoRegistryConstructorBased extends AbstractIoRegistry {
- public CustomIoRegistryConstructorBased() {
- register(GryoIo.class, Junk.class, null);
- }
- }
-
- public static class CustomIoRegistryInstanceBased extends AbstractIoRegistry {
- private static CustomIoRegistryInstanceBased INSTANCE = new CustomIoRegistryInstanceBased();
-
- private CustomIoRegistryInstanceBased() {
- register(GryoIo.class, Junk.class, null);
- }
-
- public static CustomIoRegistryInstanceBased getInstance() {
- return INSTANCE;
- }
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d33fb15f/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GryoMessageSerializerV1d0.java
----------------------------------------------------------------------
diff --git a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GryoMessageSerializerV1d0.java b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GryoMessageSerializerV1d0.java
index 1c63046..04742ac 100644
--- a/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GryoMessageSerializerV1d0.java
+++ b/gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/ser/GryoMessageSerializerV1d0.java
@@ -26,16 +26,17 @@ import org.apache.tinkerpop.gremlin.driver.message.RequestMessage;
import org.apache.tinkerpop.gremlin.driver.message.ResponseMessage;
import org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode;
import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.io.IoRegistry;
import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoIo;
import org.apache.tinkerpop.gremlin.structure.io.gryo.GryoMapper;
import org.apache.tinkerpop.shaded.kryo.Kryo;
import org.apache.tinkerpop.shaded.kryo.Serializer;
import org.apache.tinkerpop.shaded.kryo.io.Input;
import org.apache.tinkerpop.shaded.kryo.io.Output;
-import org.javatuples.Pair;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
+import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
@@ -44,7 +45,6 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
-import java.util.function.Function;
import java.util.stream.Collectors;
/**
@@ -64,6 +64,7 @@ public final class GryoMessageSerializerV1d0 implements MessageSerializer {
private static final String MIME_TYPE = SerTokens.MIME_GRYO_V1D0;
private static final String MIME_TYPE_STRINGD = SerTokens.MIME_GRYO_V1D0 + "-stringd";
+ private static final String TOKEN_IO_REGISTRIES = "ioRegistries";
private static final String TOKEN_CUSTOM = "custom";
private static final String TOKEN_SERIALIZE_RESULT_TO_STRING = "serializeResultToString";
private static final String TOKEN_USE_MAPPER_FROM_GRAPH = "useMapperFromGraph";
@@ -109,13 +110,38 @@ public final class GryoMessageSerializerV1d0 implements MessageSerializer {
builder = GryoMapper.build();
}
- final List<String> classNameList;
- try {
- classNameList = (List<String>) config.getOrDefault(TOKEN_CUSTOM, new ArrayList<String>());
- } catch (Exception ex) {
- throw new IllegalStateException(String.format("Invalid configuration value of [%s] for [%s] setting on %s serialization configuration",
- config.getOrDefault(TOKEN_CUSTOM, ""), TOKEN_CUSTOM, this.getClass().getName()), ex);
- }
+ addIoRegistries(config, builder);
+ addCustomClasses(config, builder);
+
+ this.serializeToString = Boolean.parseBoolean(config.getOrDefault(TOKEN_SERIALIZE_RESULT_TO_STRING, "false").toString());
+
+ this.gryoMapper = builder.create();
+ }
+
+ private void addIoRegistries(final Map<String, Object> config, final GryoMapper.Builder builder) {
+ final List<String> classNameList = getClassNamesFromConfig(TOKEN_IO_REGISTRIES, config);
+
+ classNameList.stream().forEach(className -> {
+ try {
+ final Class<?> clazz = Class.forName(className);
+ try {
+ final Method instanceMethod = clazz.getDeclaredMethod("getInstance");
+ if (IoRegistry.class.isAssignableFrom(instanceMethod.getReturnType()))
+ builder.addRegistry((IoRegistry) instanceMethod.invoke(null));
+ else
+ throw new Exception();
+ } catch (Exception methodex) {
+ // tried getInstance() and that failed so try newInstance() no-arg constructor
+ builder.addRegistry((IoRegistry) clazz.newInstance());
+ }
+ } catch (Exception ex) {
+ throw new IllegalStateException(ex);
+ }
+ });
+ }
+
+ private void addCustomClasses(final Map<String, Object> config, final GryoMapper.Builder builder) {
+ final List<String> classNameList = getClassNamesFromConfig(TOKEN_CUSTOM, config);
classNameList.stream().forEach(serializerDefinition -> {
String className;
@@ -145,10 +171,17 @@ public final class GryoMessageSerializerV1d0 implements MessageSerializer {
throw new IllegalStateException("Class could not be found", ex);
}
});
+ }
- this.serializeToString = Boolean.parseBoolean(config.getOrDefault(TOKEN_SERIALIZE_RESULT_TO_STRING, "false").toString());
-
- this.gryoMapper = builder.create();
+ private List<String> getClassNamesFromConfig(final String token, final Map<String, Object> config) {
+ final List<String> classNameList;
+ try {
+ classNameList = (List<String>) config.getOrDefault(token, new ArrayList<String>());
+ } catch (Exception ex) {
+ throw new IllegalStateException(String.format("Invalid configuration value of [%s] for [%s] setting on %s serialization configuration",
+ config.getOrDefault(token, ""), token, this.getClass().getName()), ex);
+ }
+ return classNameList;
}
@Override
[10/10] incubator-tinkerpop git commit: Merge remote-tracking branch
'origin/tp30'
Posted by sp...@apache.org.
Merge remote-tracking branch 'origin/tp30'
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/acbe9b11
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/acbe9b11
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/acbe9b11
Branch: refs/heads/master
Commit: acbe9b11606b4a74bfad94834880d69fd52b5291
Parents: 792103d 5311329
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jul 31 13:04:55 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Jul 31 13:04:55 2015 -0400
----------------------------------------------------------------------
docs/src/gremlin-applications.asciidoc | 5 +-
docs/src/intro.asciidoc | 2 +-
docs/src/the-graph.asciidoc | 2 +-
.../tinkerpop/gremlin/structure/Graph.java | 15 ++++-
.../gremlin/structure/Transaction.java | 40 +++++------
.../gremlin/structure/io/IoRegistry.java | 5 +-
.../tinkerpop/gremlin/structure/io/Mapper.java | 6 +-
.../structure/io/graphson/GraphSONIo.java | 3 +-
.../structure/io/graphson/GraphSONMapper.java | 8 +--
.../gremlin/structure/io/gryo/GryoIo.java | 2 +-
.../gremlin/structure/io/gryo/GryoMapper.java | 9 +--
.../gremlin/structure/io/gryo/GryoPool.java | 55 ++++++++++-----
.../tinkerpop/gremlin/structure/io/IoX.java | 50 ++++++++++++++
.../gremlin/structure/io/IoXIoRegistry.java | 44 ++++++++++++
.../tinkerpop/gremlin/structure/io/IoY.java | 52 +++++++++++++++
.../gremlin/structure/io/IoYIoRegistry.java | 44 ++++++++++++
.../structure/io/gryo/GryoMapperTest.java | 70 +++++++++++++++++++-
.../gremlin/structure/io/gryo/GryoPoolTest.java | 62 ++++++++---------
.../driver/ser/GryoMessageSerializerV1d0.java | 57 ++++++++++++----
.../server/GremlinDriverIntegrateTest.java | 27 ++++++++
.../gremlin/structure/TransactionTest.java | 44 +++++++-----
.../gremlin/neo4j/structure/Neo4jGraph.java | 5 --
22 files changed, 481 insertions(+), 126 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/acbe9b11/docs/src/gremlin-applications.asciidoc
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/acbe9b11/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/gryo/GryoMapper.java
----------------------------------------------------------------------
[02/10] incubator-tinkerpop git commit: Fix broken link.
Posted by sp...@apache.org.
Fix broken link.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/31aeb13c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/31aeb13c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/31aeb13c
Branch: refs/heads/master
Commit: 31aeb13c33a71c3b40157a71a452802032323f6b
Parents: 46e5144
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Tue Jul 28 09:31:54 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Tue Jul 28 09:31:54 2015 -0400
----------------------------------------------------------------------
docs/src/gremlin-applications.asciidoc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/31aeb13c/docs/src/gremlin-applications.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/gremlin-applications.asciidoc b/docs/src/gremlin-applications.asciidoc
index c4ea18e..e38af95 100644
--- a/docs/src/gremlin-applications.asciidoc
+++ b/docs/src/gremlin-applications.asciidoc
@@ -672,7 +672,7 @@ scriptEngines: {
"org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.TimedInterruptCustomizerProvider":[10000],
"org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.CompileStaticCustomizerProvider":["org.apache.tinkerpop.gremlin.groovy.jsr223.customizer.SimpleSandboxExtension"]}}}}
-NOTE: The above configuration could also use the `TypeCheckedCustomizerProvider` in place of the `CompileStaticCustomizerProvider`. The differences between `TypeChecked` and `CompileStatic` are beyond the scope of this documentation. Consult the latest link:http://docs.groovy-lang.org/latest/html/documentation/#_typing[Groovy Documentation' for information on the differences. It is important to understand the impact that these configuration will have on submitted scripts before enabling this feature.
+NOTE: The above configuration could also use the `TypeCheckedCustomizerProvider` in place of the `CompileStaticCustomizerProvider`. The differences between `TypeChecked` and `CompileStatic` are beyond the scope of this documentation. Consult the latest link:http://docs.groovy-lang.org/latest/html/documentation/#_typing[Groovy Documentation] for information on the differences. It is important to understand the impact that these configuration will have on submitted scripts before enabling this feature.
This configuration uses the `SimpleSandboxExtension`, which blacklists calls to methods on the `System` class, thereby preventing someone from remotely killing the server:
[07/10] incubator-tinkerpop git commit: Update javadoc around
transactions/close behavor.
Posted by sp...@apache.org.
Update javadoc around transactions/close behavor.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/1359dc80
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/1359dc80
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/1359dc80
Branch: refs/heads/master
Commit: 1359dc8045ce200ca169b072d98d283d4ece1c69
Parents: 1ba7723
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jul 31 08:25:17 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Jul 31 08:25:17 2015 -0400
----------------------------------------------------------------------
.../org/apache/tinkerpop/gremlin/structure/Graph.java | 11 ++++++-----
.../apache/tinkerpop/gremlin/structure/Transaction.java | 9 +++++----
.../tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java | 1 -
3 files changed, 11 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1359dc80/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
index d4c15d8..355f824 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Graph.java
@@ -246,11 +246,12 @@ public interface Graph extends AutoCloseable, Host {
public Transaction tx();
/**
- * Closing a {@code Graph} is equivalent to "shutdown". Users should consult the documentation of the underlying
- * graph database implementation for what this "shutdown" will mean as it pertains to open transactions. It will
- * typically be the end user's responsibility to synchronize the thread that calls {@code close()} with other
- * threads that are accessing open transactions. In other words, be sure that all work performed on the
- * {@code Graph} instance is complete prior to calling this method.
+ * Closing a {@code Graph} is equivalent to "shutdown" and implies that no futher operations can be executed on
+ * the instance. Users should consult the documentation of the underlying graph database implementation for what
+ * this "shutdown" will mean as it pertains to open transactions. It will typically be the end user's
+ * responsibility to synchronize the thread that calls {@code close()} with other threads that are accessing open
+ * transactions. In other words, be sure that all work performed on the {@code Graph} instance is complete prior
+ * to calling this method.
*/
@Override
void close() throws Exception;
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1359dc80/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java
index 14a346e..820649a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java
@@ -83,7 +83,8 @@ public interface Transaction extends Closeable {
public void readWrite();
/**
- * Closes the transaction where the default close behavior will be executed.
+ * Closes the transaction where the default close behavior defined by {{@link #onClose(Consumer)}} will be
+ * executed.
*/
@Override
public void close();
@@ -161,7 +162,7 @@ public interface Transaction extends Closeable {
*/
public enum CLOSE_BEHAVIOR implements Consumer<Transaction> {
/**
- * Any open transaction will commit on close.
+ * Commit the transaction when {@link #close()} is called.
*/
COMMIT {
@Override
@@ -171,7 +172,7 @@ public interface Transaction extends Closeable {
},
/**
- * Any open transaction will rollback on close.
+ * Rollback the transaction when {@link #close()} is called.
*/
ROLLBACK {
@Override
@@ -181,7 +182,7 @@ public interface Transaction extends Closeable {
},
/**
- * Open transactions on close will throw an exception
+ * Throw an exception if the current transaction is open when {@link #close()} is called.
*/
MANUAL {
@Override
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1359dc80/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
index 4c1b87b..3d1c0e0 100644
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
+++ b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
@@ -272,7 +272,6 @@ public final class Neo4jGraph implements Graph, WrappedGraph<Neo4jGraphAPI> {
return this.configuration;
}
-
/**
* This implementation of {@code close} will also close the current transaction on the the thread, but it
* is up to the caller to deal with dangling transactions in other threads prior to calling this method.
[09/10] incubator-tinkerpop git commit: Add a session test for
ensuring results return in order.
Posted by sp...@apache.org.
Add a session test for ensuring results return in order.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/53113298
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/53113298
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/53113298
Branch: refs/heads/master
Commit: 53113298e1802fd4d14b5fb13e101d81b18fa38d
Parents: 7e4c80d
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jul 31 12:58:34 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Jul 31 12:58:34 2015 -0400
----------------------------------------------------------------------
.../server/GremlinDriverIntegrateTest.java | 27 ++++++++++++++++++++
1 file changed, 27 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/53113298/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
----------------------------------------------------------------------
diff --git a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
index c31337c..407436c 100644
--- a/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
+++ b/gremlin-server/src/test/java/org/apache/tinkerpop/gremlin/server/GremlinDriverIntegrateTest.java
@@ -47,6 +47,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@@ -145,6 +146,32 @@ public class GremlinDriverIntegrateTest extends AbstractGremlinServerIntegration
}
@Test
+ public void shouldProcessSessionRequestsInOrder() throws Exception {
+ final Cluster cluster = Cluster.open();
+ final Client client = cluster.connect(name.getMethodName());
+
+ final ResultSet rsFive = client.submit("Thread.sleep(5000);'five'");
+ final ResultSet rsZero = client.submit("'zero'");
+
+ final CompletableFuture<List<Result>> futureFive = rsFive.all();
+ final CompletableFuture<List<Result>> futureZero = rsZero.all();
+
+ final AtomicBoolean hit = new AtomicBoolean(false);
+ while (!futureFive.isDone()) {
+ // futureZero can't finish before futureFive - racy business here?
+ assertThat(futureZero.isDone(), is(false));
+ hit.set(true);
+ }
+
+ // should have entered the loop at least once and thus proven that futureZero didn't return ahead of
+ // futureFive
+ assertThat(hit.get(), is(true));
+
+ assertEquals("zero", futureZero.get().get(0).getString());
+ assertEquals("five", futureFive.get(10, TimeUnit.SECONDS).get(0).getString());
+ }
+
+ @Test
public void shouldWaitForAllResultsToArrive() throws Exception {
final Cluster cluster = Cluster.open();
final Client client = cluster.connect();
[08/10] incubator-tinkerpop git commit: Alter semantics of
Transaction.close() in relation to Graph.close().
Posted by sp...@apache.org.
Alter semantics of Transaction.close() in relation to Graph.close().
More info on TINKERPOP3-764. As a result of this change Neo4jGraph doesn't need to OptOut of one of the TransactionTests anymore.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/7e4c80dd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/7e4c80dd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/7e4c80dd
Branch: refs/heads/master
Commit: 7e4c80ddba1da41cff9b3c688b1b40fc7d58b948
Parents: 1359dc8
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jul 31 12:21:15 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Jul 31 12:21:15 2015 -0400
----------------------------------------------------------------------
docs/src/the-graph.asciidoc | 2 +-
.../gremlin/structure/TransactionTest.java | 44 ++++++++++++--------
.../gremlin/neo4j/structure/Neo4jGraph.java | 4 --
3 files changed, 27 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7e4c80dd/docs/src/the-graph.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/the-graph.asciidoc b/docs/src/the-graph.asciidoc
index 007b4ff..c27c432 100644
--- a/docs/src/the-graph.asciidoc
+++ b/docs/src/the-graph.asciidoc
@@ -176,7 +176,7 @@ Providing a `Consumer` function to `onReadWrite` allows definition of how a tran
* `AUTO` - automatic transactions where the transaction is started implicitly to the read or write operation
* `MANUAL` - manual transactions where it is up to the user to explicitly open a transaction, throwing an exception if the transaction is not open
-Providing a `Consumer` function to `onClose` allows configuration of how a transaction is handled when `Graph.close()` is called. `Transaction.CLOSE_BEHAVIOR` has several pre-defined options that can be supplied to this method:
+Providing a `Consumer` function to `onClose` allows configuration of how a transaction is handled when `Transaction.close()` is called. `Transaction.CLOSE_BEHAVIOR` has several pre-defined options that can be supplied to this method:
* `COMMIT` - automatically commit an open transaction
* `ROLLBACK` - automatically rollback an open transaction
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7e4c80dd/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/TransactionTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/TransactionTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/TransactionTest.java
index 7d6c7c6..5736be8 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/TransactionTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/TransactionTest.java
@@ -79,7 +79,7 @@ public class TransactionTest extends AbstractGremlinTest {
g.tx().open();
try {
- graph.close();
+ graph.tx().close();
fail("An exception should be thrown when close behavior is manual and the graph is close with an open transaction");
} catch (Exception ex) {
validateException(Transaction.Exceptions.openTransactionsOnClose(), ex);
@@ -357,13 +357,17 @@ public class TransactionTest extends AbstractGremlinTest {
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_PERSISTENCE)
- public void shouldCommitOnShutdownByDefault() throws Exception {
- final Vertex v1 = graph.addVertex("name", "marko");
- final Object oid = v1.id();
- graph.close();
+ public void shouldCommitOnCloseByDefault() throws Exception {
+ final AtomicReference<Object> oid = new AtomicReference<>();
+ final Thread t = new Thread(() -> {
+ final Vertex v1 = graph.addVertex("name", "marko");
+ oid.set(v1.id());
+ graph.tx().close();
+ });
+ t.start();
+ t.join();
- graph = graphProvider.openTestGraph(config);
- final Vertex v2 = graph.vertices(oid).next();
+ final Vertex v2 = graph.vertices(oid.get()).next();
assertEquals("marko", v2.<String>value("name"));
}
@@ -371,23 +375,27 @@ public class TransactionTest extends AbstractGremlinTest {
@FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_TRANSACTIONS)
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_PERSISTENCE)
- public void shouldRollbackOnShutdownWhenConfigured() throws Exception {
- final Vertex v2 = graph.addVertex("name", "stephen");
- graph.tx().commit();
-
- final Vertex v1 = graph.addVertex("name", "marko");
- final Object oid = v1.id();
- g.tx().onClose(Transaction.CLOSE_BEHAVIOR.ROLLBACK);
- graph.close();
+ public void shouldRollbackOnCloseWhenConfigured() throws Exception {
+ final AtomicReference<Object> oid = new AtomicReference<>();
+ final AtomicReference<Vertex> vid = new AtomicReference<>();
+ final Thread t = new Thread(() -> {
+ vid.set(graph.addVertex("name", "stephen"));
+ graph.tx().commit();
- graph = graphProvider.openTestGraph(config);
+ final Vertex v1 = graph.addVertex("name", "marko");
+ oid.set(v1.id());
+ g.tx().onClose(Transaction.CLOSE_BEHAVIOR.ROLLBACK);
+ graph.tx().close();
+ });
+ t.start();
+ t.join();
// this was committed
- assertTrue(graph.vertices(v2.id()).hasNext());
+ assertTrue(graph.vertices(vid.get().id()).hasNext());
try {
// this was not
- graph.vertices(oid).next();
+ graph.vertices(oid.get()).next();
fail("Vertex should not be found as close behavior was set to rollback");
} catch (Exception ex) {
validateException(Graph.Exceptions.elementNotFound(Vertex.class, oid), ex);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/7e4c80dd/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
index 3d1c0e0..17b9976 100644
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
+++ b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/structure/Neo4jGraph.java
@@ -71,10 +71,6 @@ import java.util.stream.Stream;
@Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT_INTEGRATE)
@Graph.OptIn(Graph.OptIn.SUITE_GROOVY_ENVIRONMENT_PERFORMANCE)
@Graph.OptIn("org.apache.tinkerpop.gremlin.neo4j.NativeNeo4jSuite")
-@Graph.OptOut(
- test = "org.apache.tinkerpop.gremlin.structure.TransactionTest",
- method = "shouldRollbackOnShutdownWhenConfigured",
- reason = "There appears to be a race condition that occurs between Graph.close() and Neo4jGraphAPI.shutdown()")
public final class Neo4jGraph implements Graph, WrappedGraph<Neo4jGraphAPI> {
public static final Logger LOGGER = LoggerFactory.getLogger(Neo4jGraph.class);
[06/10] incubator-tinkerpop git commit: Update javadoc.
Posted by sp...@apache.org.
Update javadoc.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/1ba77237
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/1ba77237
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/1ba77237
Branch: refs/heads/master
Commit: 1ba77237ae340592869da9b4532223f402cb2c25
Parents: 58b699e
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Jul 31 08:11:16 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Jul 31 08:11:16 2015 -0400
----------------------------------------------------------------------
.../java/org/apache/tinkerpop/gremlin/structure/Transaction.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/1ba77237/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java
index d80c87f..14a346e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/Transaction.java
@@ -156,7 +156,8 @@ public interface Transaction extends Closeable {
}
/**
- * Behaviors to supply to the {@link #onClose(Consumer)}.
+ * Behaviors to supply to the {@link #onClose(Consumer)}. The semantics of these behaviors must be examined in
+ * the context of the implementation. In most cases, these behaviors will be applied as {{@link ThreadLocal}}.
*/
public enum CLOSE_BEHAVIOR implements Consumer<Transaction> {
/**