Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/3.4' into 3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen committed Oct 12, 2018
2 parents b6506ed + 6ee1cdb commit 1f20e0f
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ public void listProcedures() throws Throwable
"List the currently active config of Neo4j.", "DBMS" ),
proc( "db.constraints", "() :: (description :: STRING?)", "List all constraints in the database.", "READ" ),
proc( "db.indexes", "() :: (description :: STRING?, indexName :: STRING?, tokenNames :: LIST? OF STRING?, properties :: " +
"LIST? OF STRING?, state :: STRING?, type :: STRING?, progress :: FLOAT?, provider :: MAP?, id :: INTEGER?)",
"LIST? OF STRING?, state :: STRING?, type :: STRING?, progress :: FLOAT?, provider :: MAP?, id :: INTEGER?, " +
"failureMessage :: STRING?)",
"List all indexes in the database.", "READ" ),
proc( "db.awaitIndex", "(index :: STRING?, timeOutSeconds = 300 :: INTEGER?) :: VOID",
"Wait for an index to come online (for example: CALL db.awaitIndex(\":Person(name)\")).", "READ" ),
Expand Down Expand Up @@ -322,11 +323,11 @@ public void listAllIndexes() throws Throwable
"key", provider.getProviderDescriptor().getKey(), "version", provider.getProviderDescriptor().getVersion() );
assertThat( result, containsInAnyOrder(
new Object[]{"INDEX ON :Age(foo)", "index_1", singletonList( "Age" ), singletonList( "foo" ), "ONLINE",
"node_unique_property", 100D, pdm, indexingService.getIndexId( ageFooDescriptor )},
"node_unique_property", 100D, pdm, indexingService.getIndexId( ageFooDescriptor ), ""},
new Object[]{"INDEX ON :Person(foo)", "Unnamed index", singletonList( "Person" ),
singletonList( "foo" ), "ONLINE", "node_label_property", 100D, pdm, indexingService.getIndexId( personFooDescriptor )},
singletonList( "foo" ), "ONLINE", "node_label_property", 100D, pdm, indexingService.getIndexId( personFooDescriptor ), ""},
new Object[]{"INDEX ON :Person(foo, bar)", "Unnamed index", singletonList( "Person" ),
Arrays.asList( "foo", "bar" ), "ONLINE", "node_label_property", 100D, pdm, indexingService.getIndexId( personFooBarDescriptor )}
Arrays.asList( "foo", "bar" ), "ONLINE", "node_label_property", 100D, pdm, indexingService.getIndexId( personFooBarDescriptor ), ""}
) );
commit();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright (c) 2002-2018 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.api.integrationtest;

import org.junit.Test;

import java.util.Collections;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

import org.neo4j.collection.RawIterator;
import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.internal.kernel.api.Transaction;
import org.neo4j.internal.kernel.api.exceptions.ProcedureException;
import org.neo4j.kernel.api.schema.LabelSchemaDescriptor;
import org.neo4j.kernel.impl.index.schema.FailingGenericNativeIndexProviderFactory;
import org.neo4j.test.TestGraphDatabaseFactory;

import static java.util.concurrent.TimeUnit.MINUTES;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.neo4j.internal.kernel.api.procs.ProcedureSignature.procedureName;
import static org.neo4j.internal.kernel.api.security.LoginContext.AUTH_DISABLED;
import static org.neo4j.kernel.api.schema.SchemaDescriptorFactory.forLabel;
import static org.neo4j.kernel.impl.index.schema.FailingGenericNativeIndexProviderFactory.FailureType.POPULATION;
import static org.neo4j.test.TestGraphDatabaseFactory.INDEX_PROVIDERS_FILTER;

public class DbIndexesFailureMessageIT extends KernelIntegrationTest
{
private AtomicBoolean failNextIndexPopulation = new AtomicBoolean();

@Test
public void listAllIndexesWithFailedIndex() throws Throwable
{
// Given
Transaction transaction = newTransaction( AUTH_DISABLED );
int failedLabel = transaction.tokenWrite().labelGetOrCreateForName( "Fail" );
int propertyKeyId1 = transaction.tokenWrite().propertyKeyGetOrCreateForName( "foo" );
failNextIndexPopulation.set( true );
LabelSchemaDescriptor descriptor = forLabel( failedLabel, propertyKeyId1 );
transaction.schemaWrite().indexCreate( descriptor );
commit();

//let indexes come online
try ( org.neo4j.graphdb.Transaction ignored = db.beginTx() )
{
db.schema().awaitIndexesOnline( 2, MINUTES );
fail( "Expected to fail when awaiting for index to come online" );
}
catch ( IllegalStateException e )
{
// expected
}

// When
RawIterator<Object[],ProcedureException> stream =
procs().procedureCallRead( procs().procedureGet( procedureName( "db", "indexes" ) ).id(),
new Object[0] );
assertTrue( stream.hasNext() );
Object[] result = stream.next();
assertFalse( stream.hasNext() );

// Then
assertEquals( "INDEX ON :Fail(foo)", result[0] );
assertEquals( "Unnamed index", result[1] );
assertEquals( Collections.singletonList( "Fail" ), result[2] );
assertEquals( Collections.singletonList( "foo" ), result[3] );
assertEquals( "FAILED", result[4] );
assertEquals( "node_label_property", result[5] );
assertEquals( 0.0, result[6] );
Map<String,String> providerDescriptionMap = MapUtil.stringMap(
"key", GraphDatabaseSettings.SchemaIndex.NATIVE_BTREE10.providerKey(),
"version", GraphDatabaseSettings.SchemaIndex.NATIVE_BTREE10.providerVersion() );
assertEquals( providerDescriptionMap, result[7] );
assertEquals( indexingService.getIndexId( descriptor ), result[8] );
assertThat( (String) result[9], containsString( "java.lang.RuntimeException: Fail on update during population" ) );

commit();
}

@Override
protected TestGraphDatabaseFactory createGraphDatabaseFactory()
{
return super.createGraphDatabaseFactory()
.removeKernelExtensions( INDEX_PROVIDERS_FILTER )
.addKernelExtension( new FailingGenericNativeIndexProviderFactory( POPULATION ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.helpers.collection.PrefetchingResourceIterator;
import org.neo4j.internal.kernel.api.IndexReference;
import org.neo4j.internal.kernel.api.InternalIndexState;
import org.neo4j.internal.kernel.api.NodeExplicitIndexCursor;
import org.neo4j.internal.kernel.api.RelationshipExplicitIndexCursor;
import org.neo4j.internal.kernel.api.SchemaRead;
Expand Down Expand Up @@ -147,10 +148,12 @@ public Stream<IndexResult> listIndexes() throws ProcedureException
List<String> tokenNames = Arrays.asList( tokens.entityTokensGetNames( schema.entityType(), schema.getEntityTokenIds() ) );
List<String> propertyNames = propertyNames( tokens, index );
String description = "INDEX ON " + schema.userDescription( tokens );
String state = schemaRead.indexGetState( index ).toString();
InternalIndexState internalIndexState = schemaRead.indexGetState( index );
String state = internalIndexState.toString();
Map<String,String> providerDescriptorMap = indexProviderDescriptorMap( schemaRead.index( schema ) );
PopulationProgress progress = schemaRead.indexGetPopulationProgress( index );
IndexPopulationProgress indexProgress = new IndexPopulationProgress( progress.getCompleted(), progress.getTotal() );
String failureMessage = internalIndexState == InternalIndexState.FAILED ? schemaRead.indexGetFailure( index ) : "";
result.add( new IndexResult( indexId,
description,
index.name(),
Expand All @@ -159,7 +162,8 @@ public Stream<IndexResult> listIndexes() throws ProcedureException
state,
type,
indexProgress.getCompletedPercentage(),
providerDescriptorMap ) );
providerDescriptorMap,
failureMessage ) );
}
catch ( IndexNotFoundKernelException e )
{
Expand Down Expand Up @@ -878,6 +882,7 @@ public static class IndexResult
public final Double progress;
public final Map<String,String> provider;
public final long id;
public final String failureMessage;

private IndexResult( long id,
String description,
Expand All @@ -887,7 +892,8 @@ private IndexResult( long id,
String state,
String type,
Float progress,
Map<String,String> provider )
Map<String,String> provider,
String failureMessage )
{
this.id = id;
this.description = description;
Expand All @@ -898,6 +904,7 @@ private IndexResult( long id,
this.type = type;
this.progress = progress.doubleValue();
this.provider = provider;
this.failureMessage = failureMessage;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void shouldListAllIndexes() throws Throwable
// When/Then
assertThat( call( "db.indexes" ), contains( record(
"INDEX ON :User(name)", "Unnamed index", singletonList( "User" ), singletonList( "name" ), "ONLINE", "node_label_property", 100D,
getIndexProviderDescriptorMap( EMPTY.getProviderDescriptor() ), 42L ) ) );
getIndexProviderDescriptorMap( EMPTY.getProviderDescriptor() ), 42L, "" ) ) );
}

@Test
Expand All @@ -183,7 +183,7 @@ public void shouldListAllUniqueIndexes() throws Throwable
// When/Then
assertThat( call( "db.indexes" ), contains( record(
"INDEX ON :User(name)", "Unnamed index", singletonList( "User" ), singletonList( "name" ), "ONLINE", "node_unique_property", 100D,
getIndexProviderDescriptorMap( EMPTY.getProviderDescriptor() ), 42L ) ) );
getIndexProviderDescriptorMap( EMPTY.getProviderDescriptor() ), 42L, "" ) ) );
}

@Test
Expand Down Expand Up @@ -271,8 +271,8 @@ public void shouldListCorrectBuiltinProcedures() throws Throwable
record( "db.constraints", "db.constraints() :: (description :: STRING?)",
"List all constraints in the database.", "READ" ),
record( "db.indexes", "db.indexes() :: (description :: STRING?, indexName :: STRING?, " +
"tokenNames :: LIST? OF STRING?, properties :: LIST? OF STRING?, " +
"state :: STRING?, type :: STRING?, progress :: FLOAT?, provider :: MAP?, id :: INTEGER?)",
"tokenNames :: LIST? OF STRING?, properties :: LIST? OF STRING?, state :: STRING?, " +
"type :: STRING?, progress :: FLOAT?, provider :: MAP?, id :: INTEGER?, failureMessage :: STRING?)",
"List all indexes in the database.", "READ" ),
record( "db.labels", "db.labels() :: (label :: STRING?)", "List all labels in the database.", "READ" ),
record( "db.propertyKeys", "db.propertyKeys() :: (propertyKey :: STRING?)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class BuiltInProcedureAcceptanceTest extends ProcedureCallAcceptanceTest with Cy
//When
val result = executeWith(combinedCallconfiguration, "CALL db.labels() YIELD label WHERE label <> 'A' RETURN *")

// Then
// ThenBuiltInProceduresIT.java:136
result.toList should equal(
List(
Map("label" -> "B"),
Expand Down Expand Up @@ -288,7 +288,8 @@ class BuiltInProcedureAcceptanceTest extends ProcedureCallAcceptanceTest with Cy
"id" -> 1,
"provider" -> Map(
"version" -> GenericNativeIndexProvider.DESCRIPTOR.getVersion,
"key" -> GenericNativeIndexProvider.DESCRIPTOR.getKey))))
"key" -> GenericNativeIndexProvider.DESCRIPTOR.getKey),
"failureMessage" -> "")))
}

test("yield from void procedure should return correct error msg") {
Expand Down Expand Up @@ -326,7 +327,8 @@ class BuiltInProcedureAcceptanceTest extends ProcedureCallAcceptanceTest with Cy
"id" -> 1,
"provider" -> Map(
"version" -> "1.0",
"key" -> "lucene+native"))))
"key" -> "lucene+native"),
"failureMessage" -> "" )))
}

test("should create unique property constraint from built-in-procedure") {
Expand Down Expand Up @@ -359,6 +361,7 @@ class BuiltInProcedureAcceptanceTest extends ProcedureCallAcceptanceTest with Cy
mapResult("provider") should equal(Map(
"version" -> "1.0",
"key" -> "lucene+native"))
mapResult("failureMessage") should equal("")
}

test("should create node key constraint from built-in-procedure") {
Expand Down Expand Up @@ -391,5 +394,6 @@ class BuiltInProcedureAcceptanceTest extends ProcedureCallAcceptanceTest with Cy
mapResult("provider") should equal(Map(
"version" -> "1.0",
"key" -> "lucene+native"))
mapResult("failureMessage") should equal("")
}
}

0 comments on commit 1f20e0f

Please sign in to comment.