Search in sources :

Example 1 with BaseTransactionConfig

use of org.janusgraph.diskstorage.BaseTransactionConfig in project janusgraph by JanusGraph.

the class CassandraTransactionTest method testTimestampProvider.

@Test
public void testTimestampProvider() {
    BaseTransactionConfig baseTransactionConfig = StandardBaseTransactionConfig.of(TimestampProviders.NANO);
    CassandraTransaction ct = new CassandraTransaction(baseTransactionConfig);
    assertEquals(TimestampProviders.NANO, ct.getConfiguration().getTimestampProvider());
    baseTransactionConfig = StandardBaseTransactionConfig.of(TimestampProviders.MICRO);
    ct = new CassandraTransaction(baseTransactionConfig);
    assertEquals(TimestampProviders.MICRO, ct.getConfiguration().getTimestampProvider());
    baseTransactionConfig = StandardBaseTransactionConfig.of(TimestampProviders.MILLI);
    ct = new CassandraTransaction(baseTransactionConfig);
    assertEquals(TimestampProviders.MILLI, ct.getConfiguration().getTimestampProvider());
}
Also used : StandardBaseTransactionConfig(org.janusgraph.diskstorage.util.StandardBaseTransactionConfig) BaseTransactionConfig(org.janusgraph.diskstorage.BaseTransactionConfig) Test(org.junit.Test)

Example 2 with BaseTransactionConfig

use of org.janusgraph.diskstorage.BaseTransactionConfig in project janusgraph by JanusGraph.

the class ElasticSearchConfigTest method testExternalDynamic.

@Test
public void testExternalDynamic() throws Exception {
    final Duration maxWrite = Duration.ofMillis(2000L);
    final String storeName = "test_mapping";
    final Configuration indexConfig = GraphDatabaseConfiguration.buildGraphConfiguration().set(USE_EXTERNAL_MAPPINGS, true, INDEX_NAME).restrictTo(INDEX_NAME);
    final IndexProvider idx = open(indexConfig);
    final ElasticMajorVersion version = ((ElasticSearchIndex) idx).getVersion();
    // Test create index KO mapping is not push
    final KeyInformation.IndexRetriever indexRetriever = IndexProviderTest.getIndexRetriever(IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD));
    final BaseTransactionConfig txConfig = StandardBaseTransactionConfig.of(TimestampProviders.MILLI);
    final IndexTransaction itx = new IndexTransaction(idx, indexRetriever, txConfig, maxWrite);
    try {
        idx.register(storeName, "date", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("date"), itx);
        fail("should fail");
    } catch (final PermanentBackendException ignored) {
    }
    final HttpPut newMapping = new HttpPut("janusgraph_" + storeName);
    newMapping.setEntity(new StringEntity(objectMapper.writeValueAsString(readMapping(version, "/dynamic_mapping.json")), Charset.forName("UTF-8")));
    executeRequest(newMapping);
    // Test date property OK
    idx.register(storeName, "date", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("date"), itx);
    // Test weight property OK  because dynamic mapping
    idx.register(storeName, "weight", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("weight"), itx);
    itx.rollback();
    idx.close();
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) Configuration(org.janusgraph.diskstorage.configuration.Configuration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Duration(java.time.Duration) StandardBaseTransactionConfig(org.janusgraph.diskstorage.util.StandardBaseTransactionConfig) BaseTransactionConfig(org.janusgraph.diskstorage.BaseTransactionConfig) HttpPut(org.apache.http.client.methods.HttpPut) StringEntity(org.apache.http.entity.StringEntity) ElasticSearchIndex(org.janusgraph.diskstorage.es.ElasticSearchIndex) Test(org.junit.Test)

Example 3 with BaseTransactionConfig

use of org.janusgraph.diskstorage.BaseTransactionConfig in project janusgraph by JanusGraph.

the class ElasticSearchConfigTest method testExternalMappingsViaTemplate.

@Test
public void testExternalMappingsViaTemplate() throws Exception {
    final Duration maxWrite = Duration.ofMillis(2000L);
    final String storeName = "test_mapping";
    final Configuration indexConfig = GraphDatabaseConfiguration.buildGraphConfiguration().set(USE_EXTERNAL_MAPPINGS, true, INDEX_NAME).restrictTo(INDEX_NAME);
    final IndexProvider idx = open(indexConfig);
    final ElasticMajorVersion version = ((ElasticSearchIndex) idx).getVersion();
    final HttpPut newTemplate = new HttpPut("_template/template_1");
    final Map<String, Object> content = ImmutableMap.of("template", "janusgraph_test_mapping*", "mappings", readMapping(version, "/strict_mapping.json").getMappings());
    newTemplate.setEntity(new StringEntity(objectMapper.writeValueAsString(content), Charset.forName("UTF-8")));
    executeRequest(newTemplate);
    final HttpPut newMapping = new HttpPut("janusgraph_" + storeName);
    executeRequest(newMapping);
    final KeyInformation.IndexRetriever indexRetriever = IndexProviderTest.getIndexRetriever(IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD));
    final BaseTransactionConfig txConfig = StandardBaseTransactionConfig.of(TimestampProviders.MILLI);
    final IndexTransaction itx = new IndexTransaction(idx, indexRetriever, txConfig, maxWrite);
    // Test date property OK
    idx.register(storeName, "date", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("date"), itx);
    // Test weight property KO
    try {
        idx.register(storeName, "weight", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("weight"), itx);
        fail("should fail");
    } catch (final BackendException ignored) {
    }
    itx.rollback();
    idx.close();
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) Configuration(org.janusgraph.diskstorage.configuration.Configuration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) Duration(java.time.Duration) StandardBaseTransactionConfig(org.janusgraph.diskstorage.util.StandardBaseTransactionConfig) BaseTransactionConfig(org.janusgraph.diskstorage.BaseTransactionConfig) HttpPut(org.apache.http.client.methods.HttpPut) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) StringEntity(org.apache.http.entity.StringEntity) ElasticSearchIndex(org.janusgraph.diskstorage.es.ElasticSearchIndex) Test(org.junit.Test)

Example 4 with BaseTransactionConfig

use of org.janusgraph.diskstorage.BaseTransactionConfig in project janusgraph by JanusGraph.

the class ExpectedValueCheckingStoreManager method beginTransaction.

@Override
public ExpectedValueCheckingTransaction beginTransaction(BaseTransactionConfig configuration) throws BackendException {
    // Get a transaction without any guarantees about strong consistency
    StoreTransaction inconsistentTx = manager.beginTransaction(configuration);
    // Get a transaction that provides global strong consistency
    Configuration customOptions = new MergedConfiguration(storeFeatures.getKeyConsistentTxConfig(), configuration.getCustomOptions());
    BaseTransactionConfig consistentTxCfg = new StandardBaseTransactionConfig.Builder(configuration).customOptions(customOptions).build();
    StoreTransaction strongConsistentTx = manager.beginTransaction(consistentTxCfg);
    // Return a wrapper around both the inconsistent and consistent store transactions
    return new ExpectedValueCheckingTransaction(inconsistentTx, strongConsistentTx, maxReadTime);
}
Also used : MergedConfiguration(org.janusgraph.diskstorage.configuration.MergedConfiguration) Configuration(org.janusgraph.diskstorage.configuration.Configuration) MergedConfiguration(org.janusgraph.diskstorage.configuration.MergedConfiguration) StandardBaseTransactionConfig(org.janusgraph.diskstorage.util.StandardBaseTransactionConfig) BaseTransactionConfig(org.janusgraph.diskstorage.BaseTransactionConfig)

Example 5 with BaseTransactionConfig

use of org.janusgraph.diskstorage.BaseTransactionConfig in project janusgraph by JanusGraph.

the class ElasticSearchConfigTest method testExternalMappingsViaMapping.

@Test
public void testExternalMappingsViaMapping() throws Exception {
    final Duration maxWrite = Duration.ofMillis(2000L);
    final String storeName = "test_mapping";
    final Configuration indexConfig = GraphDatabaseConfiguration.buildGraphConfiguration().set(USE_EXTERNAL_MAPPINGS, true, INDEX_NAME).restrictTo(INDEX_NAME);
    final IndexProvider idx = open(indexConfig);
    final ElasticMajorVersion version = ((ElasticSearchIndex) idx).getVersion();
    // Test create index KO mapping is not push
    final KeyInformation.IndexRetriever indexRetriever = IndexProviderTest.getIndexRetriever(IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD));
    final BaseTransactionConfig txConfig = StandardBaseTransactionConfig.of(TimestampProviders.MILLI);
    final IndexTransaction itx = new IndexTransaction(idx, indexRetriever, txConfig, maxWrite);
    try {
        idx.register(storeName, "date", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("date"), itx);
        fail("should fail");
    } catch (final PermanentBackendException ignored) {
    }
    final HttpPut newMapping = new HttpPut("janusgraph_" + storeName);
    newMapping.setEntity(new StringEntity(objectMapper.writeValueAsString(readMapping(version, "/strict_mapping.json")), Charset.forName("UTF-8")));
    executeRequest(newMapping);
    // Test date property OK
    idx.register(storeName, "date", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("date"), itx);
    // Test weight property KO
    try {
        idx.register(storeName, "weight", IndexProviderTest.getMapping(idx.getFeatures(), ANALYZER_ENGLISH, ANALYZER_KEYWORD).get("weight"), itx);
        fail("should fail");
    } catch (final BackendException ignored) {
    }
    itx.rollback();
    idx.close();
}
Also used : BaseConfiguration(org.apache.commons.configuration.BaseConfiguration) Configuration(org.janusgraph.diskstorage.configuration.Configuration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) Duration(java.time.Duration) StandardBaseTransactionConfig(org.janusgraph.diskstorage.util.StandardBaseTransactionConfig) BaseTransactionConfig(org.janusgraph.diskstorage.BaseTransactionConfig) HttpPut(org.apache.http.client.methods.HttpPut) BackendException(org.janusgraph.diskstorage.BackendException) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) StringEntity(org.apache.http.entity.StringEntity) ElasticSearchIndex(org.janusgraph.diskstorage.es.ElasticSearchIndex) Test(org.junit.Test)

Aggregations

BaseTransactionConfig (org.janusgraph.diskstorage.BaseTransactionConfig)6 StandardBaseTransactionConfig (org.janusgraph.diskstorage.util.StandardBaseTransactionConfig)6 Duration (java.time.Duration)4 Configuration (org.janusgraph.diskstorage.configuration.Configuration)4 Test (org.junit.Test)4 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)3 HttpPut (org.apache.http.client.methods.HttpPut)3 StringEntity (org.apache.http.entity.StringEntity)3 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)3 BasicConfiguration (org.janusgraph.diskstorage.configuration.BasicConfiguration)3 ModifiableConfiguration (org.janusgraph.diskstorage.configuration.ModifiableConfiguration)3 CommonsConfiguration (org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration)3 ElasticSearchIndex (org.janusgraph.diskstorage.es.ElasticSearchIndex)3 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)3 BackendException (org.janusgraph.diskstorage.BackendException)2 MergedConfiguration (org.janusgraph.diskstorage.configuration.MergedConfiguration)1