From 378b5058a8f482bed721e9c4d566c2d3236a8c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=CC=8Avard=20Ottestad?= Date: Sun, 31 Mar 2019 09:08:27 +0200 Subject: [PATCH] https://github.com/eclipse/rdf4j/issues/1290 fixed typo and reformat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: HaĚŠvard Ottestad --- .../rdf4j/sail/shacl/AST/ShaclProperties.java | 26 ++-- .../rdf4j/sail/shacl/MultithreadedTest.java | 140 +++++++++--------- .../benchmark/ShaclLoadingBenchmark.java | 121 ++++++++------- 3 files changed, 141 insertions(+), 146 deletions(-) diff --git a/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/AST/ShaclProperties.java b/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/AST/ShaclProperties.java index 979404d8a..ce72e2c70 100644 --- a/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/AST/ShaclProperties.java +++ b/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/AST/ShaclProperties.java @@ -65,67 +65,67 @@ public ShaclProperties(Resource propertyShapeId, SailRepositoryConnection connec break; case "http://www.w3.org/ns/shacl#languageIn": if (languageIn != null) { - throw new IllegalStateException("sh:languageIn already populated"); + throw new IllegalStateException(predicate + " already populated"); } languageIn = (Resource) object; break; case "http://www.w3.org/ns/shacl#nodeKind": if (nodeKind != null) { - throw new IllegalStateException("sh:nodeKind already populated"); + throw new IllegalStateException(predicate + " already populated"); } nodeKind = (Resource) object; break; case "http://www.w3.org/ns/shacl#datatype": if (datatype != null) { - throw new IllegalStateException("sh:datatype already populated"); + throw new IllegalStateException(predicate + " already populated"); } datatype = (Resource) object; break; case "http://www.w3.org/ns/shacl#minCount": if (minCount != null) { - throw new IllegalStateException("sh:minCount aleady populated"); + throw new IllegalStateException(predicate + " already populated"); } minCount = ((Literal) object).longValue(); break; case "http://www.w3.org/ns/shacl#maxCount": if (maxCount != null) { - throw new IllegalStateException("sh:maxCount aleady populated"); + throw new IllegalStateException(predicate + " already populated"); } maxCount = ((Literal) object).longValue(); break; case "http://www.w3.org/ns/shacl#minLength": if (minLength != null) { - throw new IllegalStateException("sh:minLength aleady populated"); + throw new IllegalStateException(predicate + " already populated"); } minLength = ((Literal) object).longValue(); break; case "http://www.w3.org/ns/shacl#maxLength": if (maxLength != null) { - throw new IllegalStateException("sh:maxLength aleady populated"); + throw new IllegalStateException(predicate + " already populated"); } maxLength = ((Literal) object).longValue(); break; case "http://www.w3.org/ns/shacl#minExclusive": if (minExclusive != null) { - throw new IllegalStateException("sh:minExclusive aleady populated"); + throw new IllegalStateException(predicate + " already populated"); } minExclusive = (Literal) object; break; case "http://www.w3.org/ns/shacl#maxExclusive": if (maxExclusive != null) { - throw new IllegalStateException("sh:maxExclusive aleady populated"); + throw new IllegalStateException(predicate + " already populated"); } maxExclusive = (Literal) object; break; case "http://www.w3.org/ns/shacl#minInclusive": if (minInclusive != null) { - throw new IllegalStateException("sh:minInclusive aleady populated"); + throw new IllegalStateException(predicate + " already populated"); } minInclusive = (Literal) object; break; case "http://www.w3.org/ns/shacl#maxInclusive": if (maxInclusive != null) { - throw new IllegalStateException("sh:maxInclusive aleady populated"); + throw new IllegalStateException(predicate + " already populated"); } maxInclusive = (Literal) object; break; @@ -158,13 +158,13 @@ public ShaclProperties(Resource propertyShapeId, SailRepositoryConnection connec break; case "http://www.w3.org/ns/shacl#path": if (path != null) { - throw new IllegalStateException("sh:path aleady populated"); + throw new IllegalStateException(predicate + " already populated"); } path = (Resource) object; break; case "http://www.w3.org/ns/shacl#in": if (in != null) { - throw new IllegalStateException("sh:in aleady populated"); + throw new IllegalStateException(predicate + " already populated"); } in = (Resource) object; break; diff --git a/shacl/src/test/java/org/eclipse/rdf4j/sail/shacl/MultithreadedTest.java b/shacl/src/test/java/org/eclipse/rdf4j/sail/shacl/MultithreadedTest.java index 73bb9eed0..5af774d53 100644 --- a/shacl/src/test/java/org/eclipse/rdf4j/sail/shacl/MultithreadedTest.java +++ b/shacl/src/test/java/org/eclipse/rdf4j/sail/shacl/MultithreadedTest.java @@ -41,13 +41,13 @@ public void testDataAndShapes() { Transaction transaction = new Transaction(); String join = String.join("\n", "", - "ex:shape_" + i + "_" + j, - " a sh:NodeShape ;", - " sh:targetClass ex:Person" + j + " ;", - " sh:property [", - " sh:path ex:age ;", - " sh:minCount 1 ;", - " ] ."); + "ex:shape_" + i + "_" + j, + " a sh:NodeShape ;", + " sh:targetClass ex:Person" + j + " ;", + " sh:property [", + " sh:path ex:age ;", + " sh:minCount 1 ;", + " ] ."); transaction.add(join, RDF4J.SHACL_SHAPE_GRAPH); transactions.add(transaction); @@ -55,7 +55,6 @@ public void testDataAndShapes() { list.add(transactions); } - for (int j = 0; j < 10; j++) { ArrayList transactions = new ArrayList<>(); for (int i = 0; i < 10; i++) { @@ -63,20 +62,19 @@ public void testDataAndShapes() { String join; if (i % 2 == 0) { join = String.join("\n", "", - "ex:data_" + i + "_" + j + " a ex:Person" + j + "; ", - " ex:age" + i + " " + i + j, - " ." + "ex:data_" + i + "_" + j + " a ex:Person" + j + "; ", + " ex:age" + i + " " + i + j, + " ." ); } else { join = String.join("\n", "", - "ex:data_" + i + "_" + j + " a ex:Person" + j + "; ", - " ." + "ex:data_" + i + "_" + j + " a ex:Person" + j + "; ", + " ." ); } - transaction.add(join, null); transactions.add(transaction); } @@ -89,13 +87,13 @@ public void testDataAndShapes() { Transaction transaction = new Transaction(); String join = String.join("\n", "", - "ex:shape_" + i + "_" + j, - " a sh:NodeShape ;", - " sh:targetClass ex:Person" + j + " ;", - " sh:property [", - " sh:path ex:age ;", - " sh:minCount 1 ;", - " ] ."); + "ex:shape_" + i + "_" + j, + " a sh:NodeShape ;", + " sh:targetClass ex:Person" + j + " ;", + " sh:property [", + " sh:path ex:age ;", + " sh:minCount 1 ;", + " ] ."); transaction.remove(join, RDF4J.SHACL_SHAPE_GRAPH); transactions.add(transaction); @@ -103,7 +101,6 @@ public void testDataAndShapes() { list.add(transactions); } - for (int j = 0; j < 10; j++) { ArrayList transactions = new ArrayList<>(); for (int i = 0; i < 10; i++) { @@ -111,20 +108,19 @@ public void testDataAndShapes() { String join; if (i % 2 == 0) { join = String.join("\n", "", - "ex:data_" + i + "_" + j + " a ex:Person" + j + "; ", - " ex:age" + i + " " + i + j, - " ." + "ex:data_" + i + "_" + j + " a ex:Person" + j + "; ", + " ex:age" + i + " " + i + j, + " ." ); } else { join = String.join("\n", "", - "ex:data_" + i + "_" + j + " a ex:Person" + j + "; ", - " ." + "ex:data_" + i + "_" + j + " a ex:Person" + j + "; ", + " ." ); } - transaction.remove(join, null); transactions.add(transaction); } @@ -144,29 +140,29 @@ private void parallelTest(List> list, IsolationLevels isolatio try { list.stream() - .sorted(Comparator.comparingInt(System::identityHashCode)) - .parallel() - .forEach(transactions -> { - try (SailRepositoryConnection connection = repository.getConnection()) { - - transactions.forEach(transaction -> { - connection.begin(isolationLevel); - connection.add(transaction.addedStatements); - connection.remove(transaction.removedStatements); - try { - connection.commit(); - } catch (RepositoryException e) { - System.out.println("here"); - if (!(e.getCause() instanceof ShaclSailValidationException)) { - throw e; + .sorted(Comparator.comparingInt(System::identityHashCode)) + .parallel() + .forEach(transactions -> { + try (SailRepositoryConnection connection = repository.getConnection()) { + + transactions.forEach(transaction -> { + connection.begin(isolationLevel); + connection.add(transaction.addedStatements); + connection.remove(transaction.removedStatements); + try { + connection.commit(); + } catch (RepositoryException e) { + System.out.println("here"); + if (!(e.getCause() instanceof ShaclSailValidationException)) { + throw e; + } + connection.rollback(); } - connection.rollback(); - } - }); + }); - } + } - }); + }); } finally { try (SailRepositoryConnection connection = repository.getConnection()) { @@ -184,25 +180,25 @@ class Transaction { private void add(String turtle, IRI graph) { turtle = String.join("\n", "", - "@prefix ex: .", - "@prefix sh: .", - "@prefix xsd: .", - "@prefix foaf: .") + turtle; + "@prefix ex: .", + "@prefix sh: .", + "@prefix xsd: .", + "@prefix foaf: .") + turtle; StringReader shaclRules = new StringReader(turtle); try { Model parse = Rio.parse(shaclRules, "", RDFFormat.TURTLE); parse.stream() - .map(statement -> { - if (graph != null) { - return vf.createStatement(statement.getSubject(), statement.getPredicate(), - statement.getObject(), graph); - } + .map(statement -> { + if (graph != null) { + return vf.createStatement(statement.getSubject(), statement.getPredicate(), + statement.getObject(), graph); + } - return statement; - }) - .forEach(statement -> addedStatements.add(statement)); + return statement; + }) + .forEach(statement -> addedStatements.add(statement)); } catch (IOException e) { throw new RuntimeException(e); } @@ -211,25 +207,25 @@ private void add(String turtle, IRI graph) { private void remove(String turtle, IRI graph) { turtle = String.join("\n", "", - "@prefix ex: .", - "@prefix sh: .", - "@prefix xsd: .", - "@prefix foaf: .") + turtle; + "@prefix ex: .", + "@prefix sh: .", + "@prefix xsd: .", + "@prefix foaf: .") + turtle; StringReader shaclRules = new StringReader(turtle); try { Model parse = Rio.parse(shaclRules, "", RDFFormat.TURTLE); parse.stream() - .map(statement -> { - if (graph != null) { - return vf.createStatement(statement.getSubject(), statement.getPredicate(), - statement.getObject(), graph); - } + .map(statement -> { + if (graph != null) { + return vf.createStatement(statement.getSubject(), statement.getPredicate(), + statement.getObject(), graph); + } - return statement; - }) - .forEach(statement -> removedStatements.add(statement)); + return statement; + }) + .forEach(statement -> removedStatements.add(statement)); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/shacl/src/test/java/org/eclipse/rdf4j/sail/shacl/benchmark/ShaclLoadingBenchmark.java b/shacl/src/test/java/org/eclipse/rdf4j/sail/shacl/benchmark/ShaclLoadingBenchmark.java index d522bc4b2..dc5035c88 100644 --- a/shacl/src/test/java/org/eclipse/rdf4j/sail/shacl/benchmark/ShaclLoadingBenchmark.java +++ b/shacl/src/test/java/org/eclipse/rdf4j/sail/shacl/benchmark/ShaclLoadingBenchmark.java @@ -38,8 +38,8 @@ */ @State(Scope.Benchmark) @Warmup(iterations = 20) -@BenchmarkMode({Mode.AverageTime}) -@Fork(value = 1, jvmArgs = {"-Xms8G", "-Xmx8G", "-Xmn4G", "-XX:+UseSerialGC"}) +@BenchmarkMode({ Mode.AverageTime }) +@Fork(value = 1, jvmArgs = { "-Xms8G", "-Xmx8G", "-Xmn4G", "-XX:+UseSerialGC" }) //@Fork(value = 1, jvmArgs = {"-Xms8G", "-Xmx8G", "-Xmn4G", "-XX:+UseSerialGC", "-XX:+UnlockCommercialFeatures", "-XX:StartFlightRecording=delay=15s,duration=120s,filename=recording.jfr,settings=ProfilingAggressive.jfc", "-XX:FlightRecorderOptions=samplethreads=true,stackdepth=1024", "-XX:+UnlockDiagnosticVMOptions", "-XX:+DebugNonSafepoints"}) @Measurement(iterations = 10) @OutputTimeUnit(TimeUnit.MILLISECONDS) @@ -49,7 +49,7 @@ public class ShaclLoadingBenchmark { public void setUp() { System.gc(); ((Logger) LoggerFactory.getLogger(ShaclSailConnection.class.getName())) - .setLevel(ch.qos.logback.classic.Level.ERROR); + .setLevel(ch.qos.logback.classic.Level.ERROR); ((Logger) LoggerFactory.getLogger(ShaclSail.class.getName())).setLevel(ch.qos.logback.classic.Level.ERROR); } @@ -67,51 +67,51 @@ public void testAddingDataAndAddingShapes() throws Exception { for (int i = 0; i < 10; i++) { StringReader data = new StringReader(String.join("\n", "", - "@prefix ex: .", - "@prefix sh: .", - "@prefix xsd: .", - "@prefix foaf: .", - - "[] a ex:Person; ", - " ex:age"+i+" " + i + " .", - "[] a ex:Person; ", - " ex:age"+i+" " + i + " .", - "[] a ex:Person; ", - " ex:age"+i+" " + i + " .", - "[] a ex:Person; ", - " ex:age"+i+" " + i + " .", - "[] a ex:Person; ", - " ex:age"+i+" " + i + " .", - "[] a ex:Person; ", - " ex:age"+i+" " + i + " .", - "[] a ex:Person; ", - " ex:age"+i+" " + i + " .", - "[] a ex:Person; ", - " ex:age"+i+" " + i + " .", - "[] a ex:Person; ", - " ex:age"+i+" " + i + " .", - "[] a ex:Person; ", - " ex:age"+i+" " + i + " .", - "[] a ex:Person; ", - " ex:age"+i+" " + i + " .", - "[] a ex:Person; ", - " ex:age"+i+" " + i + " .", - "[] a ex:Person; ", - " ex:age"+i+" " + i + " .", - "[] a ex:Person; ", - " ex:age"+i+" " + i + " .", - "[] a ex:Person; ", - " ex:age"+i+" " + i + " .", - "[] a ex:Person; ", - " ex:age"+i+" " + i + " .", - "[] a ex:Person; ", - " ex:age"+i+" " + i + " .", - "[] a ex:Person; ", - " ex:age"+i+" " + i + " .", - "[] a ex:Person; ", - " ex:age"+i+" " + i + " .", - "[] a ex:Person; ", - " ex:age"+i+" " + i + " ." + "@prefix ex: .", + "@prefix sh: .", + "@prefix xsd: .", + "@prefix foaf: .", + + "[] a ex:Person; ", + " ex:age" + i + " " + i + " .", + "[] a ex:Person; ", + " ex:age" + i + " " + i + " .", + "[] a ex:Person; ", + " ex:age" + i + " " + i + " .", + "[] a ex:Person; ", + " ex:age" + i + " " + i + " .", + "[] a ex:Person; ", + " ex:age" + i + " " + i + " .", + "[] a ex:Person; ", + " ex:age" + i + " " + i + " .", + "[] a ex:Person; ", + " ex:age" + i + " " + i + " .", + "[] a ex:Person; ", + " ex:age" + i + " " + i + " .", + "[] a ex:Person; ", + " ex:age" + i + " " + i + " .", + "[] a ex:Person; ", + " ex:age" + i + " " + i + " .", + "[] a ex:Person; ", + " ex:age" + i + " " + i + " .", + "[] a ex:Person; ", + " ex:age" + i + " " + i + " .", + "[] a ex:Person; ", + " ex:age" + i + " " + i + " .", + "[] a ex:Person; ", + " ex:age" + i + " " + i + " .", + "[] a ex:Person; ", + " ex:age" + i + " " + i + " .", + "[] a ex:Person; ", + " ex:age" + i + " " + i + " .", + "[] a ex:Person; ", + " ex:age" + i + " " + i + " .", + "[] a ex:Person; ", + " ex:age" + i + " " + i + " .", + "[] a ex:Person; ", + " ex:age" + i + " " + i + " .", + "[] a ex:Person; ", + " ex:age" + i + " " + i + " ." )); @@ -123,18 +123,18 @@ public void testAddingDataAndAddingShapes() throws Exception { for (int i = 0; i < 10; i++) { connection.begin(IsolationLevels.SNAPSHOT); StringReader shaclRules = new StringReader(String.join("\n", "", - "@prefix ex: .", - "@prefix sh: .", - "@prefix xsd: .", - "@prefix foaf: .", - - "[]", - " a sh:NodeShape ;", - " sh:targetClass ex:Person ;", - " sh:property [", - " sh:path ex:age" + i + " ;", - " sh:datatype xsd:integer ;", - " ] .")); + "@prefix ex: .", + "@prefix sh: .", + "@prefix xsd: .", + "@prefix foaf: .", + + "[]", + " a sh:NodeShape ;", + " sh:targetClass ex:Person ;", + " sh:property [", + " sh:path ex:age" + i + " ;", + " sh:datatype xsd:integer ;", + " ] .")); connection.add(shaclRules, "", RDFFormat.TURTLE, RDF4J.SHACL_SHAPE_GRAPH); connection.commit(); @@ -146,5 +146,4 @@ public void testAddingDataAndAddingShapes() throws Exception { } - }