use of com.thinkaurelius.titan.core.TitanGraph in project titan by thinkaurelius.
the class ElasticSearchConfigTest method testTitanFactoryBuilder.
@Test
public void testTitanFactoryBuilder() {
String baseDir = Joiner.on(File.separator).join("target", "es", "titanfactory_jvmlocal_ext");
TitanFactory.Builder builder = TitanFactory.build();
builder.set("storage.backend", "inmemory");
builder.set("index." + INDEX_NAME + ".elasticsearch.interface", "NODE");
builder.set("index." + INDEX_NAME + ".elasticsearch.ext.node.data", "true");
builder.set("index." + INDEX_NAME + ".elasticsearch.ext.node.client", "false");
builder.set("index." + INDEX_NAME + ".elasticsearch.ext.node.local", "true");
builder.set("index." + INDEX_NAME + ".elasticsearch.ext.path.data", baseDir + File.separator + "data");
builder.set("index." + INDEX_NAME + ".elasticsearch.ext.path.work", baseDir + File.separator + "work");
builder.set("index." + INDEX_NAME + ".elasticsearch.ext.path.logs", baseDir + File.separator + "logs");
// Must not throw an exception
TitanGraph graph = builder.open();
assertTrue(graph.isOpen());
graph.close();
}
use of com.thinkaurelius.titan.core.TitanGraph in project titan by thinkaurelius.
the class TitanGraphTest method setAndCheckGraphOption.
private <T> void setAndCheckGraphOption(ConfigOption<T> opt, ConfigOption.Type requiredType, T firstValue, T secondValue) {
// Sanity check: make sure the Type of the configoption is what we expect
Preconditions.checkState(opt.getType().equals(requiredType));
final EnumSet<ConfigOption.Type> allowedTypes = EnumSet.of(ConfigOption.Type.GLOBAL, ConfigOption.Type.GLOBAL_OFFLINE, ConfigOption.Type.MASKABLE);
Preconditions.checkState(allowedTypes.contains(opt.getType()));
// Sanity check: it's kind of pointless for the first and second values to be identical
Preconditions.checkArgument(!firstValue.equals(secondValue));
// Get full string path of config option
final String path = ConfigElement.getPath(opt);
// Set and check initial value before and after database restart
mgmt.set(path, firstValue);
assertEquals(firstValue.toString(), mgmt.get(path));
// Close open tx first. This is specific to BDB + GLOBAL_OFFLINE.
// Basically: the BDB store manager throws a fit if shutdown is called
// with one or more transactions still open, and GLOBAL_OFFLINE calls
// shutdown on our behalf when we commit this change.
tx.rollback();
mgmt.commit();
clopen();
// Close tx again following clopen
tx.rollback();
assertEquals(firstValue.toString(), mgmt.get(path));
// Set and check updated value before and after database restart
mgmt.set(path, secondValue);
assertEquals(secondValue.toString(), mgmt.get(path));
mgmt.commit();
clopen();
tx.rollback();
assertEquals(secondValue.toString(), mgmt.get(path));
// Open a separate graph "g2"
TitanGraph g2 = TitanFactory.open(config);
TitanManagement m2 = g2.openManagement();
assertEquals(secondValue.toString(), m2.get(path));
// GLOBAL_OFFLINE options should be unmodifiable with g2 open
if (opt.getType().equals(ConfigOption.Type.GLOBAL_OFFLINE)) {
try {
mgmt.set(path, firstValue);
mgmt.commit();
fail("Option " + path + " with type " + ConfigOption.Type.GLOBAL_OFFLINE + " should not be modifiable with concurrent instances");
} catch (RuntimeException e) {
log.debug("Caught expected exception", e);
}
assertEquals(secondValue.toString(), mgmt.get(path));
// GLOBAL and MASKABLE should be modifiable even with g2 open
} else {
mgmt.set(path, firstValue);
assertEquals(firstValue.toString(), mgmt.get(path));
mgmt.commit();
clopen();
assertEquals(firstValue.toString(), mgmt.get(path));
}
m2.rollback();
g2.close();
}
use of com.thinkaurelius.titan.core.TitanGraph in project titan by thinkaurelius.
the class AbstractTitanGraphProvider method clear.
// @Override
// public <ID> ID reconstituteGraphSONIdentifier(final Class<? extends Element> clazz, final Object id) {
// if (Edge.class.isAssignableFrom(clazz)) {
// // TitanGraphSONModule toStrings the edgeid - expect a String value for the id
// if (!(id instanceof String)) throw new RuntimeException("Expected a String value for the RelationIdentifier");
// return (ID) RelationIdentifier.parse((String) id);
// } else {
// return (ID) id;
// }
// }
@Override
public void clear(Graph g, final Configuration configuration) throws Exception {
if (null != g) {
while (g instanceof WrappedGraph) g = ((WrappedGraph<? extends Graph>) g).getBaseGraph();
TitanGraph graph = (TitanGraph) g;
if (graph.isOpen()) {
if (g.tx().isOpen())
g.tx().rollback();
g.close();
}
}
WriteConfiguration config = new CommonsConfiguration(configuration);
BasicConfiguration readConfig = new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE);
if (readConfig.has(GraphDatabaseConfiguration.STORAGE_BACKEND)) {
TitanGraphBaseTest.clearGraph(config);
}
}
use of com.thinkaurelius.titan.core.TitanGraph in project titan by thinkaurelius.
the class AbstractTitanGraphProvider method loadGraphData.
@Override
public void loadGraphData(final Graph g, final LoadGraphWith loadGraphWith, final Class testClass, final String testName) {
if (loadGraphWith != null) {
this.createIndices((TitanGraph) g, loadGraphWith.value());
} else {
if (TransactionTest.class.equals(testClass) && testName.equalsIgnoreCase("shouldExecuteWithCompetingThreads")) {
TitanManagement mgmt = ((TitanGraph) g).openManagement();
mgmt.makePropertyKey("blah").dataType(Double.class).make();
mgmt.makePropertyKey("bloop").dataType(Integer.class).make();
mgmt.makePropertyKey("test").dataType(Object.class).make();
mgmt.makeEdgeLabel("friend").make();
mgmt.commit();
}
}
super.loadGraphData(g, loadGraphWith, testClass, testName);
}
use of com.thinkaurelius.titan.core.TitanGraph in project titan by thinkaurelius.
the class TitanFactoryShorthandTest method testTitanFactoryShorthand.
@Test
public void testTitanFactoryShorthand() {
TitanGraph g = TitanFactory.open("inmemory");
g.close();
}
Aggregations