forked from thinkaurelius/titan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed up serialization issues around Geoshape. thinkaurelius#1183
Added support for type embedded GraphSON and Gryo. Also included tests against Graph of The Gods to ensure the full write/read cycle worked.
- Loading branch information
1 parent
a1aae99
commit 6dfc816
Showing
5 changed files
with
207 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package com.thinkaurelius.titan.graphdb.tinkerpop; | ||
|
||
import com.thinkaurelius.titan.core.attribute.Geoshape; | ||
import com.thinkaurelius.titan.graphdb.relations.RelationIdentifier; | ||
import com.thinkaurelius.titan.graphdb.tinkerpop.io.graphson.TitanGraphSONModule; | ||
import org.apache.tinkerpop.gremlin.structure.io.AbstractIoRegistry; | ||
|
@@ -8,6 +9,7 @@ | |
|
||
/** | ||
* @author Matthias Broecheler ([email protected]) | ||
* @author Stephen Mallette (http://stephen.genoprime.com) | ||
*/ | ||
public class TitanIoRegistry extends AbstractIoRegistry { | ||
|
||
|
@@ -18,5 +20,6 @@ public class TitanIoRegistry extends AbstractIoRegistry { | |
public TitanIoRegistry() { | ||
register(GraphSONIo.class, null, TitanGraphSONModule.getInstance()); | ||
register(GryoIo.class, RelationIdentifier.class, null); | ||
register(GryoIo.class, Geoshape.class, new Geoshape.GeoShapeGryoSerializer()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
titan-test/src/main/java/com/thinkaurelius/titan/graphdb/TitanIoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.thinkaurelius.titan.graphdb; | ||
|
||
import com.thinkaurelius.titan.example.GraphOfTheGodsFactory; | ||
import org.apache.tinkerpop.gremlin.structure.io.GraphReader; | ||
import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; | ||
import org.apache.tinkerpop.gremlin.structure.io.IoCore; | ||
import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper; | ||
import org.junit.Test; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
|
||
/** | ||
* Tests Titan specific serialization classes not covered by the TinkerPop suite. | ||
* | ||
* @author Stephen Mallette (http://stephen.genoprime.com) | ||
*/ | ||
public abstract class TitanIoTest extends TitanGraphBaseTest { | ||
|
||
@Test | ||
public void testGeoShapeSerializationReadWriteAsGraphSONEmbedded() throws Exception { | ||
GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true); | ||
GraphSONMapper m = graph.io(IoCore.graphson()).mapper().embedTypes(true).create(); | ||
GraphWriter writer = graph.io(IoCore.graphson()).writer().mapper(m).create(); | ||
FileOutputStream fos = new FileOutputStream("/tmp/test.json"); | ||
writer.writeGraph(fos, graph); | ||
|
||
clearGraph(config); | ||
open(config); | ||
|
||
GraphReader reader = graph.io(IoCore.graphson()).reader().mapper(m).create(); | ||
FileInputStream fis = new FileInputStream("/tmp/test.json"); | ||
reader.readGraph(fis, graph); | ||
|
||
TitanIndexTest.assertGraphOfTheGods(graph); | ||
} | ||
|
||
@Test | ||
public void testGeoShapeSerializationReadWriteAsGryo() throws Exception { | ||
GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true); | ||
graph.io(IoCore.gryo()).writeGraph("/tmp/test.kryo"); | ||
|
||
clearGraph(config); | ||
open(config); | ||
|
||
graph.io(IoCore.gryo()).readGraph("/tmp/test.kryo"); | ||
|
||
TitanIndexTest.assertGraphOfTheGods(graph); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
titan-test/src/test/java/com/thinkaurelius/titan/graphdb/inmemory/InMemoryTitanIoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.thinkaurelius.titan.graphdb.inmemory; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.thinkaurelius.titan.diskstorage.configuration.ModifiableConfiguration; | ||
import com.thinkaurelius.titan.diskstorage.configuration.WriteConfiguration; | ||
import com.thinkaurelius.titan.graphdb.TitanGraphBaseTest; | ||
import com.thinkaurelius.titan.graphdb.TitanIoTest; | ||
import com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* @author Stephen Mallette (http://stephen.genoprime.com) | ||
*/ | ||
public class InMemoryTitanIoTest extends TitanIoTest { | ||
public WriteConfiguration getConfiguration() { | ||
ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration(); | ||
config.set(GraphDatabaseConfiguration.STORAGE_BACKEND,"inmemory"); | ||
return config.getConfiguration(); | ||
} | ||
|
||
@Override | ||
public void clopen(Object... settings) { | ||
if (settings!=null && settings.length>0) { | ||
if (graph!=null && graph.isOpen()) { | ||
Preconditions.checkArgument(!graph.vertices().hasNext() && | ||
!graph.edges().hasNext(),"Graph cannot be re-initialized for InMemory since that would delete all data"); | ||
graph.close(); | ||
} | ||
Map<TitanGraphBaseTest.TestConfigOption,Object> options = validateConfigOptions(settings); | ||
ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration(); | ||
config.set(GraphDatabaseConfiguration.STORAGE_BACKEND,"inmemory"); | ||
for (Map.Entry<TitanGraphBaseTest.TestConfigOption,Object> option : options.entrySet()) { | ||
config.set(option.getKey().option, option.getValue(), option.getKey().umbrella); | ||
} | ||
open(config.getConfiguration()); | ||
} | ||
newTx(); | ||
} | ||
} |