use of com.thinkaurelius.titan.diskstorage.es.ElasticSearchIndex in project titan by thinkaurelius.
the class ElasticSearchConfigTest method testLocalNodeUsingYaml.
@Test
public void testLocalNodeUsingYaml() throws BackendException, InterruptedException {
String baseDir = Joiner.on(File.separator).join("target", "es", "jvmlocal_yml");
assertFalse(new File(baseDir + File.separator + "data").exists());
ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
config.set(INDEX_CONF_FILE, Joiner.on(File.separator).join("target", "test-classes", "es_jvmlocal.yml"), INDEX_NAME);
Configuration indexConfig = config.restrictTo(INDEX_NAME);
IndexProvider idx = new ElasticSearchIndex(indexConfig);
simpleWriteAndQuery(idx);
idx.close();
assertTrue(new File(baseDir + File.separator + "data").exists());
}
use of com.thinkaurelius.titan.diskstorage.es.ElasticSearchIndex in project titan by thinkaurelius.
the class ElasticSearchConfigTest method testIndexCreationOptions.
@Test
public void testIndexCreationOptions() throws InterruptedException, BackendException {
final int shards = 77;
ElasticsearchRunner esr = new ElasticsearchRunner(".", "indexCreationOptions.yml");
esr.start();
CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
cc.set("index." + INDEX_NAME + ".elasticsearch.create.ext.number_of_shards", String.valueOf(shards));
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.cluster.name", "indexCreationOptions");
ModifiableConfiguration config = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, cc, BasicConfiguration.Restriction.NONE);
config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
Configuration indexConfig = config.restrictTo(INDEX_NAME);
IndexProvider idx = new ElasticSearchIndex(indexConfig);
simpleWriteAndQuery(idx);
ImmutableSettings.Builder settingsBuilder = ImmutableSettings.settingsBuilder();
settingsBuilder.put("discovery.zen.ping.multicast.enabled", "false");
settingsBuilder.put("discovery.zen.ping.unicast.hosts", "localhost,127.0.0.1:9300");
settingsBuilder.put("cluster.name", "indexCreationOptions");
NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().settings(settingsBuilder.build());
nodeBuilder.client(true).data(false).local(false);
Node n = nodeBuilder.build().start();
GetSettingsResponse response = n.client().admin().indices().getSettings(new GetSettingsRequest().indices("titan")).actionGet();
assertEquals(String.valueOf(shards), response.getSetting("titan", "index.number_of_shards"));
idx.close();
n.stop();
esr.stop();
}
use of com.thinkaurelius.titan.diskstorage.es.ElasticSearchIndex in project titan by thinkaurelius.
the class ElasticSearchIndexTest method testConfiguration.
@Test
public void testConfiguration() throws BackendException {
// Test that local-mode has precedence over hostname
final String index = "es";
ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
config.set(LOCAL_MODE, true, index);
config.set(CLIENT_ONLY, true, index);
config.set(INDEX_HOSTS, new String[] { "10.0.0.1" }, index);
config.set(GraphDatabaseConfiguration.INDEX_DIRECTORY, StorageSetup.getHomeDir("es"), index);
Configuration indexConfig = config.restrictTo(index);
// Shouldn't throw exception
IndexProvider idx = new ElasticSearchIndex(indexConfig);
idx.close();
config = GraphDatabaseConfiguration.buildGraphConfiguration();
config.set(LOCAL_MODE, false, index);
config.set(CLIENT_ONLY, true, index);
config.set(INDEX_HOSTS, new String[] { "10.0.0.1" }, index);
config.set(GraphDatabaseConfiguration.INDEX_DIRECTORY, StorageSetup.getHomeDir("es"), index);
indexConfig = config.restrictTo(index);
RuntimeException expectedException = null;
try {
// Should try 10.0.0.1 and throw exception
idx = new ElasticSearchIndex(indexConfig);
idx.close();
} catch (RuntimeException re) {
expectedException = re;
}
assertNotNull(expectedException);
}
use of com.thinkaurelius.titan.diskstorage.es.ElasticSearchIndex in project titan by thinkaurelius.
the class ElasticSearchConfigTest method testLocalNodeUsingExt.
@Test
public void testLocalNodeUsingExt() throws BackendException, InterruptedException {
String baseDir = Joiner.on(File.separator).join("target", "es", "jvmlocal_ext");
assertFalse(new File(baseDir + File.separator + "data").exists());
CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.data", "true");
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.client", "false");
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.node.local", "true");
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.path.data", baseDir + File.separator + "data");
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.path.work", baseDir + File.separator + "work");
cc.set("index." + INDEX_NAME + ".elasticsearch.ext.path.logs", baseDir + File.separator + "logs");
ModifiableConfiguration config = new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS, cc, BasicConfiguration.Restriction.NONE);
config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
Configuration indexConfig = config.restrictTo(INDEX_NAME);
IndexProvider idx = new ElasticSearchIndex(indexConfig);
simpleWriteAndQuery(idx);
idx.close();
assertTrue(new File(baseDir + File.separator + "data").exists());
}
use of com.thinkaurelius.titan.diskstorage.es.ElasticSearchIndex in project titan by thinkaurelius.
the class ElasticSearchConfigTest method testTransportClient.
@Test
public void testTransportClient() throws BackendException, InterruptedException {
ElasticsearchRunner esr = new ElasticsearchRunner(".", "transportClient.yml");
esr.start();
ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
config.set(INTERFACE, ElasticSearchSetup.TRANSPORT_CLIENT.toString(), INDEX_NAME);
config.set(INDEX_HOSTS, new String[] { "127.0.0.1" }, INDEX_NAME);
Configuration indexConfig = config.restrictTo(INDEX_NAME);
IndexProvider idx = new ElasticSearchIndex(indexConfig);
simpleWriteAndQuery(idx);
idx.close();
config = GraphDatabaseConfiguration.buildGraphConfiguration();
config.set(INTERFACE, ElasticSearchSetup.TRANSPORT_CLIENT.toString(), INDEX_NAME);
config.set(INDEX_HOSTS, new String[] { "10.11.12.13" }, INDEX_NAME);
indexConfig = config.restrictTo(INDEX_NAME);
Throwable failure = null;
try {
idx = new ElasticSearchIndex(indexConfig);
} catch (Throwable t) {
failure = t;
}
// idx.close();
Assert.assertNotNull("ES client failed to throw exception on connection failure", failure);
esr.stop();
}
Aggregations