Java Code Examples for com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration#buildGraphConfiguration()

The following examples show how to use com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration#buildGraphConfiguration() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CassandraTransactionTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadConsistencyLevel() {
    int levelsChecked = 0;

    // Test whether CassandraTransaction honors the write consistency level option
    for (CLevel writeLevel : CLevel.values()) {
        StandardBaseTransactionConfig.Builder b = new StandardBaseTransactionConfig.Builder();
        ModifiableConfiguration mc = GraphDatabaseConfiguration.buildGraphConfiguration();
        mc.set(CASSANDRA_READ_CONSISTENCY, writeLevel.name());
        b.timestampProvider(TimestampProviders.MICRO);
        b.customOptions(mc);
        CassandraTransaction ct = new CassandraTransaction(b.build());
        assertEquals(writeLevel, ct.getReadConsistencyLevel());
        levelsChecked++;
    }

    // Sanity check: if CLevel.values was empty, something is wrong with the test
    Preconditions.checkState(0 < levelsChecked);
}
 
Example 2
Source File: ElasticSearchConfigTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 3
Source File: CassandraTransactionTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteConsistencyLevel() {
    int levelsChecked = 0;

    // Test whether CassandraTransaction honors the write consistency level option
    for (CLevel writeLevel : CLevel.values()) {
        StandardBaseTransactionConfig.Builder b = new StandardBaseTransactionConfig.Builder();
        ModifiableConfiguration mc = GraphDatabaseConfiguration.buildGraphConfiguration();
        mc.set(CASSANDRA_WRITE_CONSISTENCY, writeLevel.name());
        b.customOptions(mc);
        b.timestampProvider(TimestampProviders.MICRO);
        CassandraTransaction ct = new CassandraTransaction(b.build());
        assertEquals(writeLevel, ct.getWriteConsistencyLevel());
        levelsChecked++;
    }

    // Sanity check: if CLevel.values was empty, something is wrong with the test
    Preconditions.checkState(0 < levelsChecked);
}
 
Example 4
Source File: HBaseStoreManager.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Override
public StoreFeatures getFeatures() {

    Configuration c = GraphDatabaseConfiguration.buildGraphConfiguration();

    StandardStoreFeatures.Builder fb = new StandardStoreFeatures.Builder()
            .orderedScan(true).unorderedScan(true).batchMutation(true)
            .multiQuery(true).distributed(true).keyOrdered(true).storeTTL(true)
            .timestamps(true).preferredTimestamps(PREFERRED_TIMESTAMPS)
            .keyConsistent(c);

    try {
        fb.localKeyPartition(getDeployment() == Deployment.LOCAL);
    } catch (Exception e) {
        logger.warn("Unexpected exception during getDeployment()", e);
    }

    return fb.build();
}
 
Example 5
Source File: InMemoryGraphTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@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<TestConfigOption,Object> options = validateConfigOptions(settings);
        ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
        config.set(GraphDatabaseConfiguration.STORAGE_BACKEND,"inmemory");
        for (Map.Entry<TestConfigOption,Object> option : options.entrySet()) {
            config.set(option.getKey().option, option.getValue(), option.getKey().umbrella);
        }
        open(config.getConfiguration());
    }
    newTx();
}
 
Example 6
Source File: VertexIDAssignerTest.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param numPartitionsBits The number of partitions bits to use. This means there are exactly (1<<numPartitionBits) partitions.
 * @param partitionMax The maxium number of ids that can be allocated per partition. This is artifically constraint by the MockIDAuthority
 * @param localPartitionDef This array contains three integers: 1+2) lower and upper bounds for the local partition range, and
 *                          3) the bit width of the local bounds. The bounds will be bitshifted forward to consume the bit width
 */
public VertexIDAssignerTest(int numPartitionsBits, int partitionMax, int[] localPartitionDef) {
    MockIDAuthority idAuthority = new MockIDAuthority(11, partitionMax);

    StandardStoreFeatures.Builder fb = new StandardStoreFeatures.Builder();

    if (null != localPartitionDef) {
        fb.localKeyPartition(true);
        idAuthority.setLocalPartition(PartitionIDRangeTest.convert(localPartitionDef[0],localPartitionDef[1],localPartitionDef[2]));
    }
    StoreFeatures features = fb.build();

    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(GraphDatabaseConfiguration.CLUSTER_MAX_PARTITIONS,1<<numPartitionsBits);
    idAssigner = new VertexIDAssigner(config, idAuthority, features);
    System.out.println(String.format("Configuration [%s|%s|%s]",numPartitionsBits,partitionMax,Arrays.toString(localPartitionDef)));

    if (localPartitionDef!=null && localPartitionDef[0]<localPartitionDef[1] && localPartitionDef[2]<=numPartitionsBits) {
        this.maxIDAssignments = ((localPartitionDef[1]-localPartitionDef[0])<<(numPartitionsBits-localPartitionDef[2]))*((long)partitionMax);
    } else {
        this.maxIDAssignments = (1<<numPartitionsBits)*((long)partitionMax);
    }
}
 
Example 7
Source File: HBaseStorageSetup.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public static ModifiableConfiguration getHBaseConfiguration(String tableName) {
        ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
        config.set(GraphDatabaseConfiguration.STORAGE_BACKEND, "hbase");
        if (!StringUtils.isEmpty(tableName)) config.set(HBaseStoreManager.HBASE_TABLE,tableName);
        config.set(GraphDatabaseConfiguration.TIMESTAMP_PROVIDER, HBaseStoreManager.PREFERRED_TIMESTAMPS);
        config.set(SimpleBulkPlacementStrategy.CONCURRENT_PARTITIONS, 1);
//        config.set(GraphDatabaseConfiguration.STORAGE_NS.getName()+"."+HBaseStoreManager.HBASE_CONFIGURATION_NAMESPACE+
//                    ".hbase.zookeeper.quorum","localhost");
//        config.set(GraphDatabaseConfiguration.STORAGE_NS.getName()+"."+HBaseStoreManager.HBASE_CONFIGURATION_NAMESPACE+
//                "hbase.zookeeper.property.clientPort",2181);
        return config;
    }
 
Example 8
Source File: ElasticSearchIndexTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@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);

    IndexProvider idx = new ElasticSearchIndex(indexConfig); // Shouldn't throw exception
    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 {
        idx = new ElasticSearchIndex(indexConfig); // Should try 10.0.0.1 and throw exception
        idx.close();
    } catch (RuntimeException re) {
        expectedException = re;
    }
    assertNotNull(expectedException);
}
 
Example 9
Source File: InMemoryPartitionGraphTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
public WriteConfiguration getBaseConfiguration() {
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(GraphDatabaseConfiguration.STORAGE_BACKEND,"inmemory");
    config.set(GraphDatabaseConfiguration.IDS_FLUSH,false);
    return config.getConfiguration();
}
 
Example 10
Source File: SerializerGraphConfiguration.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Before
public void initialize() {
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(GraphDatabaseConfiguration.STORAGE_BACKEND,"inmemory");
    config.set(GraphDatabaseConfiguration.CUSTOM_ATTRIBUTE_CLASS, TClass1.class.getName(), "attribute1");
    config.set(GraphDatabaseConfiguration.CUSTOM_SERIALIZER_CLASS, TClass1Serializer.class.getName(), "attribute1");
    config.set(GraphDatabaseConfiguration.CUSTOM_ATTRIBUTE_CLASS, TEnum.class.getName(), "attribute4");
    config.set(GraphDatabaseConfiguration.CUSTOM_SERIALIZER_CLASS, TEnumSerializer.class.getName(), "attribute4");
    graph = (StandardTitanGraph) TitanFactory.open(config);
}
 
Example 11
Source File: VertexIDAssignerTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
private static TitanGraph getInMemoryGraph() {
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(GraphDatabaseConfiguration.STORAGE_BACKEND, InMemoryStoreManager.class.getCanonicalName());
    config.set(GraphDatabaseConfiguration.IDS_FLUSH, false);
    config.set(GraphDatabaseConfiguration.IDAUTHORITY_WAIT, Duration.ofMillis(1L));
    return TitanFactory.open(config);
}
 
Example 12
Source File: QueryTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(GraphDatabaseConfiguration.STORAGE_BACKEND, InMemoryStoreManager.class.getCanonicalName());
    graph = TitanFactory.open(config);
    tx = graph.newTransaction();
}
 
Example 13
Source File: SolrIndexTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
private Configuration getLocalSolrTestConfig() {
    final String index = "solr";
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();

    config.set(SolrIndex.ZOOKEEPER_URL, SolrRunner.getMiniCluster().getZkServer().getZkAddress(), index);
    config.set(SolrIndex.WAIT_SEARCHER, true, index);
    return config.restrictTo(index);
}
 
Example 14
Source File: LockKeyColumnValueStoreTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
public void open() throws BackendException {
    manager = new KeyColumnValueStoreManager[CONCURRENCY];
    tx = new StoreTransaction[CONCURRENCY][NUM_TX];
    store = new KeyColumnValueStore[CONCURRENCY];

    for (int i = 0; i < CONCURRENCY; i++) {
        manager[i] = openStorageManager(i);
        StoreFeatures storeFeatures = manager[i].getFeatures();
        store[i] = manager[i].openDatabase(DB_NAME);
        for (int j = 0; j < NUM_TX; j++) {
            tx[i][j] = manager[i].beginTransaction(getTxConfig());
            log.debug("Began transaction of class {}", tx[i][j].getClass().getCanonicalName());
        }

        ModifiableConfiguration sc = GraphDatabaseConfiguration.buildGraphConfiguration();
        sc.set(GraphDatabaseConfiguration.LOCK_LOCAL_MEDIATOR_GROUP,concreteClassName + i);
        sc.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID,"inst"+i);
        sc.set(GraphDatabaseConfiguration.LOCK_RETRY,10);
        sc.set(GraphDatabaseConfiguration.LOCK_EXPIRE, Duration.ofMillis(EXPIRE_MS));

        if (!storeFeatures.hasLocking()) {
            Preconditions.checkArgument(storeFeatures.isKeyConsistent(),"Store needs to support some form of locking");
            KeyColumnValueStore lockerStore = manager[i].openDatabase(DB_NAME + "_lock_");
            ConsistentKeyLocker c = new ConsistentKeyLocker.Builder(lockerStore, manager[i]).fromConfig(sc).mediatorName(concreteClassName + i).build();
            store[i] = new ExpectedValueCheckingStore(store[i], c);
            for (int j = 0; j < NUM_TX; j++)
                tx[i][j] = new ExpectedValueCheckingTransaction(tx[i][j], manager[i].beginTransaction(getConsistentTxConfig(manager[i])), GraphDatabaseConfiguration.STORAGE_READ_WAITTIME.getDefaultValue());
        }
    }
}
 
Example 15
Source File: ElasticSearchConfigTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 16
Source File: KCVSLogTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Override
public LogManager openLogManager(String senderId, boolean requiresOrderPreserving) throws BackendException {
    storeManager = openStorageManager();
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID,senderId);
    config.set(GraphDatabaseConfiguration.LOG_READ_INTERVAL, Duration.ofMillis(500L), LOG_NAME);
    //To ensure that the write order is preserved in reading, we need to ensure that all writes go to the same partition
    //otherwise readers will independently read from the partitions out-of-order by design to avoid having to synchronize
    config.set(KCVSLogManager.LOG_FIXED_PARTITION, requiresOrderPreserving, LOG_NAME);
    return new KCVSLogManager(storeManager,config.restrictTo(LOG_NAME));
}
 
Example 17
Source File: InMemoryGraphTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public WriteConfiguration getConfiguration() {
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(GraphDatabaseConfiguration.STORAGE_BACKEND,"inmemory");
    return config.getConfiguration();
}
 
Example 18
Source File: InMemoryConfigurationTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public void initialize(ConfigOption option, Object value) {
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(GraphDatabaseConfiguration.STORAGE_BACKEND,"inmemory");
    config.set(option,value);
    graph = (StandardTitanGraph) TitanFactory.open(config);
}
 
Example 19
Source File: InMemoryOLAPTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
public WriteConfiguration getConfiguration() {
    ModifiableConfiguration config = GraphDatabaseConfiguration.buildGraphConfiguration();
    config.set(GraphDatabaseConfiguration.STORAGE_BACKEND,"inmemory");
    return config.getConfiguration();
}
 
Example 20
Source File: ExpectedValueCheckingTest.java    From titan1withtp3.1 with Apache License 2.0 4 votes vote down vote up
@Before
public void setupMocks() throws BackendException {

    // Initialize mock controller
    ctrl = EasyMock.createStrictControl();
    ctrl.checkOrder(true);

    // Setup some config mocks and objects
    backingManager = ctrl.createMock(KeyColumnValueStoreManager.class);
    lockerProvider = ctrl.createMock(LockerProvider.class);
    globalConfig = GraphDatabaseConfiguration.buildGraphConfiguration();
    localConfig = GraphDatabaseConfiguration.buildGraphConfiguration();
    defaultConfig = GraphDatabaseConfiguration.buildGraphConfiguration();
    // Set some properties on the configs, just so that global/local/default can be easily distinguished
    globalConfig.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID, "global");
    localConfig.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID, "local");
    defaultConfig.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID, "default");
    defaultTxConfig = new StandardBaseTransactionConfig.Builder().customOptions(defaultConfig).timestampProvider(TimestampProviders.MICRO).build();
    backingFeatures = new StandardStoreFeatures.Builder().keyConsistent(globalConfig, localConfig).build();


    // Setup behavior specification starts below this line


    // 1. Construct manager
    // The EVCSManager ctor retrieves the backing store's features and stores it in an instance field
    expect(backingManager.getFeatures()).andReturn(backingFeatures).once();

    // 2. Begin transaction
    // EVCTx begins two transactions on the backingManager: one with globalConfig and one with localConfig
    // The capture is used in the @After method to check the config
    txConfigCapture = new Capture<BaseTransactionConfig>(CaptureType.ALL);
    inconsistentTx = ctrl.createMock(StoreTransaction.class);
    consistentTx = ctrl.createMock(StoreTransaction.class);
    expect(backingManager.beginTransaction(capture(txConfigCapture))).andReturn(inconsistentTx);
    expect(backingManager.beginTransaction(capture(txConfigCapture))).andReturn(consistentTx);

    // 3. Open a database
    backingLocker = ctrl.createMock(Locker.class);
    backingStore = ctrl.createMock(KeyColumnValueStore.class);
    expect(backingManager.openDatabase(STORE_NAME)).andReturn(backingStore);
    expect(backingStore.getName()).andReturn(STORE_NAME);
    expect(lockerProvider.getLocker(LOCKER_NAME)).andReturn(backingLocker);

    // Carry out setup behavior against mocks
    ctrl.replay();
    // 1. Construct manager
    expectManager = new ExpectedValueCheckingStoreManager(backingManager, LOCK_SUFFIX, lockerProvider, Duration.ofSeconds(1L));
    // 2. Begin transaction
    expectTx = expectManager.beginTransaction(defaultTxConfig);
    // 3. Open a database
    expectStore = expectManager.openDatabase(STORE_NAME);

    // Verify behavior and reset the mocks for test methods to use
    ctrl.verify();
    ctrl.reset();
}