Skip to content

Commit

Permalink
Fixed Test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jexp committed Aug 6, 2018
1 parent df7a41a commit 42e81be
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/main/java/apoc/load/Xml.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private Stream<MapResult> xmlXpathToMapResult(@Name("url") String url, boolean s

FileUtils.checkReadAllowed(url);

Map<String, Object> headers = (HashMap) config.getOrDefault( "headers", Collections.emptyMap() );
Map<String, Object> headers = (Map) config.getOrDefault( "headers", Collections.emptyMap() );

Document doc = documentBuilder.parse(Util.openInputStream(url, headers, null));
XPathFactory xPathFactory = XPathFactory.newInstance();
Expand Down
58 changes: 30 additions & 28 deletions src/main/java/apoc/schema/Schemas.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

Expand Down Expand Up @@ -256,23 +257,14 @@ private Boolean constraintsExistsForRelationship(String type, List<String> prope
*/
private Stream<IndexConstraintNodeInfo> indexesAndConstraintsForNode() throws IndexNotFoundKernelException {
Schema schema = db.schema();
Stream<IndexConstraintNodeInfo> indexes = Stream.empty();

try ( Statement statement = tx.acquireStatement() ) {
ReadOperations readOps = statement.readOperations();
StatementTokenNameLookup tokens = new StatementTokenNameLookup(readOps);
Iterable<IndexDescriptor> indexesIterator = readOps::indexesGetAll;
indexes = StreamSupport.stream(indexesIterator.spliterator(), false)
.map(indexReference -> {
try {
return this.nodeInfoFromIndexDefinition(indexReference, readOps, tokens);
} catch (IndexNotFoundKernelException e) {
throw new RuntimeException("",e);
}
});
return StreamSupport.stream(indexesIterator.spliterator(), false)
.map(indexReference -> this.nodeInfoFromIndexDefinition(indexReference, readOps, tokens))
.sorted(Comparator.comparing(i -> i.label));
}

return indexes;
}

/**
Expand All @@ -295,23 +287,33 @@ private Stream<ConstraintRelationshipInfo> constraintsForRelationship() {
* @param schemaRead
* @return
*/
private IndexConstraintNodeInfo nodeInfoFromIndexDefinition(IndexDescriptor indexReference, ReadOperations schemaRead, TokenNameLookup tokens) throws IndexNotFoundKernelException {
private IndexConstraintNodeInfo nodeInfoFromIndexDefinition(IndexDescriptor indexReference, ReadOperations schemaRead, TokenNameLookup tokens) {
String labelName = tokens.labelGetName(indexReference.schema().getLabelId());
List<String> properties = new ArrayList<>();
Arrays.stream(indexReference.schema().getPropertyIds()).forEach((i) -> properties.add(tokens.propertyKeyGetName(i)));
return new IndexConstraintNodeInfo(
// Pretty print for index name
String.format(":%s(%s)", labelName, StringUtils.join(properties, ",")),
labelName,
properties,
schemaRead.indexGetState(indexReference).toString(),
indexReference.type() == IndexDescriptor.Type.UNIQUE ? "UNIQUENESS" : "INDEX",
schemaRead.indexGetState(indexReference).equals(InternalIndexState.FAILED) ? schemaRead.indexGetFailure(indexReference) : "NO FAILURE",
schemaRead.indexGetPopulationProgress(indexReference).getCompleted()/schemaRead.indexGetPopulationProgress(indexReference).getTotal()*100,
schemaRead.indexSize(indexReference),
schemaRead.indexUniqueValuesSelectivity(indexReference),
indexReference.userDescription(tokens)
);
List<String> properties = Arrays.stream(indexReference.schema().getPropertyIds()).mapToObj(tokens::propertyKeyGetName).collect(Collectors.toList());
try {
return new IndexConstraintNodeInfo(
// Pretty print for index name
String.format(":%s(%s)", labelName, StringUtils.join(properties, ",")),
labelName,
properties,
schemaRead.indexGetState(indexReference).toString(),
indexReference.type() == IndexDescriptor.Type.UNIQUE ? "UNIQUENESS" : "INDEX",
schemaRead.indexGetState(indexReference).equals(InternalIndexState.FAILED) ? schemaRead.indexGetFailure(indexReference) : "NO FAILURE",
schemaRead.indexGetPopulationProgress(indexReference).getCompleted()/schemaRead.indexGetPopulationProgress(indexReference).getTotal()*100,
schemaRead.indexSize(indexReference),
schemaRead.indexUniqueValuesSelectivity(indexReference),
indexReference.userDescription(tokens)
);
} catch (IndexNotFoundKernelException e) {
return new IndexConstraintNodeInfo(
// Pretty print for index name
String.format(":%s(%s)", labelName, StringUtils.join(properties, ",")),
labelName, properties, "NOT_FOUND",
indexReference.type() == IndexDescriptor.Type.UNIQUE ? "UNIQUENESS" : "INDEX",
"NOT_FOUND", 0, 0, 0,
indexReference.userDescription(tokens)
);
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/apoc/refactor/GraphRefactoringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,9 @@ public void testMergeNodesAndMergeSameRelationshipsAndNodes() {
assertEquals(4,resultingNode.getDegree(Direction.OUTGOING));
assertEquals(1,c.getDegree(Direction.INCOMING));
assertEquals(true, r.isType(RelationshipType.withName("HAS_REL")));
assertEquals(Arrays.asList( "r1" , "r2").toArray(), new ArrayBackedList(r.getProperty("p")).toArray());
assertEquals("r1", r.getProperty("p"));
assertEquals(true, r1.isType(RelationshipType.withName("HAS_REL")));
assertEquals(Arrays.asList( "r2" , "r1").toArray(), new ArrayBackedList(r1.getProperty("p")).toArray());
assertEquals("r2", r1.getProperty("p"));
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/apoc/schema/SchemasTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public void testIndexes() {
assertEquals("NO FAILURE", r.get("failure"));
assertEquals(new Double(100), r.get("populationProgress"));
assertEquals(new Double(1), r.get("valuesSelectivity"));
assertEquals("Index( GENERAL, bar )", r.get("userDescription"));
assertEquals("Index( GENERAL, :Foo(bar) )", r.get("userDescription"));

assertTrue(!result.hasNext());
});
Expand Down

0 comments on commit 42e81be

Please sign in to comment.