private static Map<String,String> indexProviderDescriptorMap( IndexReference indexReference ) { return MapUtil.stringMap( "key", indexReference.providerKey(), "version", indexReference.providerVersion() ); }
private static String unexpectedIndexProviderMessage( IndexReference index ) { return "Unexpected provider: key=" + index.providerKey() + ", version=" + index.providerVersion(); } }
private static void assertIndexHasExpectedProvider( IndexProviderDescriptor expectedDescriptor, IndexReference index ) { assertEquals( expectedDescriptor.getKey(), index.providerKey(), "same key" ); assertEquals( expectedDescriptor.getVersion(), index.providerVersion(), "same version" ); }
@Test public void shouldGetVersionAndKeyFromIndexReference() { // Given int label = token.nodeLabel( "Node" ); int prop = token.propertyKey( "prop" ); IndexReference index = schemaRead.index( label, prop ); assertEquals( providerKey(), index.providerKey() ); assertEquals( providerVersion(), index.providerVersion() ); }
private void assertIndexProvider( GraphDatabaseService db, String expectedProviderIdentifier ) throws IndexNotFoundKernelException { GraphDatabaseAPI graphDatabaseAPI = (GraphDatabaseAPI) db; try ( Transaction tx = graphDatabaseAPI.beginTx() ) { KernelTransaction ktx = graphDatabaseAPI.getDependencyResolver() .resolveDependency( ThreadToStatementContextBridge.class ) .getKernelTransactionBoundToThisThread( true ); TokenRead tokenRead = ktx.tokenRead(); int labelId = tokenRead.nodeLabel( LABEL.name() ); int propertyId = tokenRead.propertyKey( KEY ); IndexReference index = ktx.schemaRead().index( labelId, propertyId ); assertEquals( "expected IndexProvider.Descriptor", expectedProviderIdentifier, new IndexProviderDescriptor( index.providerKey(), index.providerVersion() ).name() ); tx.success(); } }
@Test public void batchInserterShouldUseConfiguredIndexProvider() throws Exception { Config config = Config.defaults( stringMap( default_schema_provider.name(), schemaIndex.providerName() ) ); BatchInserter inserter = newBatchInserter( config ); inserter.createDeferredSchemaIndex( TestLabels.LABEL_ONE ).on( "key" ).create(); inserter.shutdown(); GraphDatabaseService db = graphDatabaseService( config ); awaitIndexesOnline( db ); try ( Transaction tx = db.beginTx() ) { DependencyResolver dependencyResolver = ((GraphDatabaseAPI) db).getDependencyResolver(); ThreadToStatementContextBridge threadToStatementContextBridge = dependencyResolver.resolveDependency( ThreadToStatementContextBridge.class ); KernelTransaction kernelTransaction = threadToStatementContextBridge.getKernelTransactionBoundToThisThread( true ); TokenRead tokenRead = kernelTransaction.tokenRead(); SchemaRead schemaRead = kernelTransaction.schemaRead(); int labelId = tokenRead.nodeLabel( TestLabels.LABEL_ONE.name() ); int propertyId = tokenRead.propertyKey( "key" ); IndexReference index = schemaRead.index( labelId, propertyId ); assertTrue( unexpectedIndexProviderMessage( index ), schemaIndex.providerName().contains( index.providerKey() ) ); assertTrue( unexpectedIndexProviderMessage( index ), schemaIndex.providerName().contains( index.providerVersion() ) ); tx.success(); } finally { db.shutdown(); } }
private static Map<String,String> indexProviderDescriptorMap( IndexReference indexReference ) { return MapUtil.stringMap( "key", indexReference.providerKey(), "version", indexReference.providerVersion() ); }