diff --git a/qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/compact/bitmap/MultiLayerBitmapWrapper.java b/qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/compact/bitmap/MultiLayerBitmapWrapper.java index 548426c4..d1de1892 100644 --- a/qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/compact/bitmap/MultiLayerBitmapWrapper.java +++ b/qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/compact/bitmap/MultiLayerBitmapWrapper.java @@ -53,7 +53,7 @@ private MultiLayerBitmapWrapper(Bitmap handle, long graphs) { @SuppressWarnings("unchecked") public T getHandle() { - return (T)handle; + return (T) handle; } @Override diff --git a/qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/options/HDTOptions.java b/qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/options/HDTOptions.java index 13615376..25444cc1 100644 --- a/qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/options/HDTOptions.java +++ b/qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/options/HDTOptions.java @@ -155,6 +155,7 @@ static HDTOptions of(Object... data) { /** * create modifiable options with a string config + * * @param cfg config * @return options */ @@ -587,6 +588,7 @@ default void setOptions(Map options) { /** * add options from another set + * * @param other other set */ default void setOptions(HDTOptions other) { diff --git a/qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/triples/impl/BitmapTriplesIndexFile.java b/qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/triples/impl/BitmapTriplesIndexFile.java index 77ce6ba4..78f34936 100644 --- a/qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/triples/impl/BitmapTriplesIndexFile.java +++ b/qendpoint-core/src/main/java/com/the_qa_company/qendpoint/core/triples/impl/BitmapTriplesIndexFile.java @@ -62,6 +62,7 @@ public static Path getIndexPath(Path hdt, TripleComponentOrder order) { /** * Compute triples signature + * * @param triples triples * @return signature */ @@ -76,7 +77,7 @@ public static long signature(BitmapTriples triples) { * * @param file file * @param channel channel - * @param triples triples + * @param triples triples * @return index * @throws IOException io */ diff --git a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/compiler/CompiledSail.java b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/compiler/CompiledSail.java index 67c3e319..20df439e 100644 --- a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/compiler/CompiledSail.java +++ b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/compiler/CompiledSail.java @@ -349,7 +349,6 @@ public static class CompiledSailCompiler { private Model configModel; private NotifyingSail sourceSail; private EndpointFiles endpointFiles; - private HDTOptions spec; private HDTOptions hdtSpec; private final Map stringConfig = new HashMap<>(); private final List stringObject = new ArrayList<>(); @@ -523,7 +522,6 @@ public CompiledSailCompiler withHDTSpec(String hdtSpec) { return withHDTSpec(spec); } - /** * set the hdt spec for the endpoint store, won't be used if the source * is defined or if the generated source isn't an endpoint store diff --git a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/compiler/CompiledSailOptions.java b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/compiler/CompiledSailOptions.java index 1d5451d1..ed5099b7 100644 --- a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/compiler/CompiledSailOptions.java +++ b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/compiler/CompiledSailOptions.java @@ -96,7 +96,8 @@ void readOptions(SailCompiler.SailCompilerReader reader) { endpointThreshold = reader.searchPropertyValue(SailCompilerSchema.MAIN, SailCompilerSchema.ENDPOINT_THRESHOLD); hdtReadMode = reader.searchPropertyValue(SailCompilerSchema.MAIN, SailCompilerSchema.HDT_READ_MODE_PROPERTY); port = reader.searchPropertyValue(SailCompilerSchema.MAIN, SailCompilerSchema.SERVER_PORT); - hdtSpec = HDTOptions.of(reader.searchPropertyValue(SailCompilerSchema.MAIN, SailCompilerSchema.HDT_SPEC_PROPERTY)); + hdtSpec = HDTOptions + .of(reader.searchPropertyValue(SailCompilerSchema.MAIN, SailCompilerSchema.HDT_SPEC_PROPERTY)); timeoutUpdate = reader.searchPropertyValue(SailCompilerSchema.MAIN, SailCompilerSchema.TIMEOUT_UPDATE); timeoutQuery = reader.searchPropertyValue(SailCompilerSchema.MAIN, SailCompilerSchema.TIMEOUT_QUERY); hdtOptions = reader.search(SailCompilerSchema.MAIN, SailCompilerSchema.GEN_HDT_OPTION_PARAM).stream() diff --git a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/EndpointStore.java b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/EndpointStore.java index 7188027a..479ba76a 100644 --- a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/EndpointStore.java +++ b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/EndpointStore.java @@ -443,7 +443,9 @@ public void setFreezedStoreStore(AbstractNotifyingSail sail) { } /** - * force access to the store via reflection, the library does not allow directly since the method is protected + * force access to the store via reflection, the library does not allow + * directly since the method is protected + * * @return sailstore * @deprecated use {@link #getCurrentSailStore()} instead */ @@ -451,8 +453,11 @@ public void setFreezedStoreStore(AbstractNotifyingSail sail) { public SailStore getCurrentSaliStore() { return getCurrentSailStore(); } + /** - * force access to the store via reflection, the library does not allow directly since the method is protected + * force access to the store via reflection, the library does not allow + * directly since the method is protected + * * @return sailstore */ public SailStore getCurrentSailStore() { @@ -684,7 +689,8 @@ public void initTempDump(boolean isRestarting) { Files.createFile(file.toPath()); } OutputStream rdfWriterTempTriplesOut = new BufferedOutputStream(new FileOutputStream(file, isRestarting)); - this.rdfWriterTempTriples = graph ? new NQuadsWriter(rdfWriterTempTriplesOut) : new NTriplesWriter(rdfWriterTempTriplesOut); + this.rdfWriterTempTriples = graph ? new NQuadsWriter(rdfWriterTempTriplesOut) + : new NTriplesWriter(rdfWriterTempTriplesOut); this.rdfWriterTempTriples.startRDF(); } catch (IOException e) { e.printStackTrace(); diff --git a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/EndpointStoreConnection.java b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/EndpointStoreConnection.java index c5439fbf..3e2ef82d 100644 --- a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/EndpointStoreConnection.java +++ b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/EndpointStoreConnection.java @@ -268,7 +268,8 @@ public void addStatement(UpdateContext op, Resource subj, IRI pred, Value obj, R } if (!this.endpoint.getHdt().getDictionary().supportGraphs()) { - // note that in the native store we insert a mix of native IRIs and HDT + // note that in the native store we insert a mix of native IRIs and + // HDT // IRIs, depending if the resource is in // HDT or not TripleID tripleID = new TripleID(subjectID, predicateID, objectID); @@ -276,8 +277,8 @@ public void addStatement(UpdateContext op, Resource subj, IRI pred, Value obj, R // check if we need to search over the other native connection if (endpoint.isMerging()) { if (endpoint.shouldSearchOverRDF4J(subjectID, predicateID, objectID)) { - try (CloseableIteration other = getOtherConnectionRead().getStatements(newSubj, - newPred, newObj, false)) { + try (CloseableIteration other = getOtherConnectionRead() + .getStatements(newSubj, newPred, newObj, false)) { if (other.hasNext()) { return; } @@ -305,17 +306,15 @@ public void addStatement(UpdateContext op, Resource subj, IRI pred, Value obj, R if (graphID == -1) { newGraph = contexts; } else { - newGraph = new Resource[] { - this.endpoint.getHdtConverter().graphIdToIRI(graphID) - }; + newGraph = new Resource[] { this.endpoint.getHdtConverter().graphIdToIRI(graphID) }; } TripleID tripleID = new TripleID(subjectID, predicateID, objectID, graphID); if (quadDoesntExistInHDT(tripleID)) { // check if we need to search over the other native connection if (endpoint.isMerging()) { if (endpoint.shouldSearchOverRDF4J(subjectID, predicateID, objectID)) { - try (CloseableIteration other = getOtherConnectionRead().getStatements(newSubj, - newPred, newObj, false, newGraph)) { + try (CloseableIteration other = getOtherConnectionRead() + .getStatements(newSubj, newPred, newObj, false, newGraph)) { if (other.hasNext()) { return; } @@ -331,9 +330,7 @@ public void addStatement(UpdateContext op, Resource subj, IRI pred, Value obj, R this.endpoint.triplesCount++; } } else { - Resource[] newGraph = new Resource[] { - null - }; + Resource[] newGraph = new Resource[] { null }; for (Resource context : contexts) { long graphID; if (context != null) { @@ -349,11 +346,12 @@ public void addStatement(UpdateContext op, Resource subj, IRI pred, Value obj, R } TripleID tripleID = new TripleID(subjectID, predicateID, objectID, graphID); if (quadDoesntExistInHDT(tripleID)) { - // check if we need to search over the other native connection + // check if we need to search over the other native + // connection if (endpoint.isMerging()) { if (endpoint.shouldSearchOverRDF4J(subjectID, predicateID, objectID)) { - try (CloseableIteration other = getOtherConnectionRead().getStatements(newSubj, - newPred, newObj, false, newGraph)) { + try (CloseableIteration other = getOtherConnectionRead() + .getStatements(newSubj, newPred, newObj, false, newGraph)) { if (other.hasNext()) { continue; } @@ -591,10 +589,13 @@ private boolean tripleDoesntExistInHDT(TripleID tripleID) { return this.endpoint .getDeleteBitMap( iter.isLastTriplePositionBoundToOrder() ? iter.getOrder() : TripleComponentOrder.SPO) - .access(endpoint.getHdt().getDictionary().supportGraphs() ? (tid.isQuad() ? tid.getGraph() : endpoint.getHdtProps().getDefaultGraph()) - 1 : 0, index); + .access(endpoint.getHdt().getDictionary().supportGraphs() + ? (tid.isQuad() ? tid.getGraph() : endpoint.getHdtProps().getDefaultGraph()) - 1 + : 0, index); } return true; } + private boolean quadDoesntExistInHDT(TripleID tripleID) { IteratorTripleID iter = endpoint.getHdt().getTriples().search(tripleID); // if iterator is empty then the given triple 't' doesn't exist in HDT @@ -604,12 +605,13 @@ private boolean quadDoesntExistInHDT(TripleID tripleID) { return this.endpoint .getDeleteBitMap( iter.isLastTriplePositionBoundToOrder() ? iter.getOrder() : TripleComponentOrder.SPO) - .access((tid.isQuad() ? tid.getGraph() : endpoint.getHdtProps().getDefaultGraph()) - 1, index); + .access((tid.isQuad() ? tid.getGraph() : endpoint.getHdtProps().getDefaultGraph()) - 1, index); } return true; } - private void assignBitMapDeletes(TripleID tid, Resource subj, IRI pred, Value obj, Resource[] contexts, long[] contextIds) throws SailException { + private void assignBitMapDeletes(TripleID tid, Resource subj, IRI pred, Value obj, Resource[] contexts, + long[] contextIds) throws SailException { long s = tid.getSubject(); long p = tid.getPredicate(); long o = tid.getObject(); @@ -646,7 +648,8 @@ private void assignBitMapDeletes(TripleID tid, Resource subj, IRI pred, Value ob this.endpoint.getTempDeleteBitMap(sorder).set(layer, index, true); } if (order == TripleComponentOrder.SPO) { - notifyStatementRemoved(this.endpoint.getValueFactory().createStatement(subj, pred, obj)); + notifyStatementRemoved( + this.endpoint.getValueFactory().createStatement(subj, pred, obj)); } } } @@ -668,14 +671,15 @@ private void assignBitMapDeletes(TripleID tid, Resource subj, IRI pred, Value ob assert iter.isLastTriplePositionBoundToOrder(); TripleComponentOrder sorder = iter.getOrder(); - if (!this.endpoint.getDeleteBitMap(sorder).access(removedId.getGraph() - 1, index)) { this.endpoint.getDeleteBitMap(sorder).set(removedId.getGraph() - 1, index, true); if (this.endpoint.isMerging()) { - this.endpoint.getTempDeleteBitMap(sorder).set(removedId.getGraph() - 1, index, true); + this.endpoint.getTempDeleteBitMap(sorder).set(removedId.getGraph() - 1, index, + true); } if (order == TripleComponentOrder.SPO) { - notifyStatementRemoved(this.endpoint.getValueFactory().createStatement(subj, pred, obj, context)); + notifyStatementRemoved( + this.endpoint.getValueFactory().createStatement(subj, pred, obj, context)); } } } @@ -695,7 +699,8 @@ private void assignBitMapDeletes(TripleID tid, Resource subj, IRI pred, Value ob writer.handleStatement(this.endpoint.getValueFactory().createStatement(subj, pred, obj)); } else { for (Resource ctx : contexts) { - writer.handleStatement(this.endpoint.getValueFactory().createStatement(subj, pred, obj, ctx)); + writer.handleStatement( + this.endpoint.getValueFactory().createStatement(subj, pred, obj, ctx)); } } } diff --git a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/EndpointStoreTripleIterator.java b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/EndpointStoreTripleIterator.java index 1c082838..cd2e202a 100644 --- a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/EndpointStoreTripleIterator.java +++ b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/EndpointStoreTripleIterator.java @@ -8,9 +8,7 @@ import org.eclipse.rdf4j.model.Resource; import org.eclipse.rdf4j.model.Statement; import org.eclipse.rdf4j.model.Value; -import org.eclipse.rdf4j.query.QueryEvaluationException; import org.eclipse.rdf4j.query.QueryInterruptedException; -import org.eclipse.rdf4j.sail.SailException; import com.the_qa_company.qendpoint.core.triples.IteratorTripleID; import com.the_qa_company.qendpoint.core.triples.TripleID; import org.slf4j.Logger; @@ -65,7 +63,9 @@ public boolean hasNext() { logger.trace("From HDT {} {} {} ", subject, predicate, object); } if (supportGraphs) { - Resource ctx = tripleID.isQuad() ? endpoint.getHdtConverter().idToGraphHDTResource(tripleID.getGraph()) : null; + Resource ctx = tripleID.isQuad() + ? endpoint.getHdtConverter().idToGraphHDTResource(tripleID.getGraph()) + : null; next = endpointTripleSource.getValueFactory().createStatement(subject, predicate, object, ctx); } else { next = endpointTripleSource.getValueFactory().createStatement(subject, predicate, object); @@ -81,8 +81,7 @@ public boolean hasNext() { Value newObject = endpoint.getHdtConverter().rdf4jToHdtIDobject(stm.getObject()); Resource newContext = endpoint.getHdtConverter().rdf4jToHdtIDcontext(stm.getContext()); - next = endpointTripleSource.getValueFactory().createStatement(newSubj, newPred, newObject, - newContext); + next = endpointTripleSource.getValueFactory().createStatement(newSubj, newPred, newObject, newContext); if (logger.isTraceEnabled()) { logger.trace("From RDF4j {} {} {}", next.getSubject(), next.getPredicate(), next.getObject()); } diff --git a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/EndpointTripleSource.java b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/EndpointTripleSource.java index 94f1b58b..8ddb03d2 100644 --- a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/EndpointTripleSource.java +++ b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/EndpointTripleSource.java @@ -128,7 +128,7 @@ public CloseableIteration getStatements(StatementOrder stat newContextes = contexts; } - //logger.debug("SEARCH {} {} {}", newSubj, newPred, newObj); + // logger.debug("SEARCH {} {} {}", newSubj, newPred, newObj); // check if we need to search over the delta and if yes, search CloseableIteration repositoryResult; @@ -161,7 +161,8 @@ public CloseableIteration getStatements(StatementOrder stat // iterate over the HDT file IteratorTripleID iterator; if (subjectID != -1 && predicateID != -1 && objectID != -1) { - //logger.debug("Searching over HDT {} {} {}", subjectID, predicateID, objectID); + // logger.debug("Searching over HDT {} {} {}", subjectID, + // predicateID, objectID); TripleID t = new TripleID(subjectID, predicateID, objectID); if (graph && contexts.length > 1) { @@ -169,10 +170,13 @@ public CloseableIteration getStatements(StatementOrder stat int indexMaskMatchingStatementOrder = getIndexMaskMatchingStatementOrder(statementOrder, subj, pred, obj, t); - // search with the ID to check if the triples has been deleted - iterator = new GraphFilteringTripleId(this.endpoint.getHdt().getTriples().search(t, indexMaskMatchingStatementOrder), graphID); + // search with the ID to check if the triples has been + // deleted + iterator = new GraphFilteringTripleId( + this.endpoint.getHdt().getTriples().search(t, indexMaskMatchingStatementOrder), graphID); } else { - // search with the ID to check if the triples has been deleted + // search with the ID to check if the triples has been + // deleted iterator = new GraphFilteringTripleId(this.endpoint.getHdt().getTriples().search(t), graphID); } } else { @@ -183,10 +187,12 @@ public CloseableIteration getStatements(StatementOrder stat int indexMaskMatchingStatementOrder = getIndexMaskMatchingStatementOrder(statementOrder, subj, pred, obj, t); - // search with the ID to check if the triples has been deleted + // search with the ID to check if the triples has been + // deleted iterator = this.endpoint.getHdt().getTriples().search(t, indexMaskMatchingStatementOrder); } else { - // search with the ID to check if the triples has been deleted + // search with the ID to check if the triples has been + // deleted iterator = this.endpoint.getHdt().getTriples().search(t); } } @@ -277,8 +283,7 @@ private int getIndexMaskMatchingStatementOrder(StatementOrder statementOrder, Re throw new AssertionError( "Statement order " + statementOrder + " not supported for triple pattern " + t.getPatternString()); } - int indexMaskMatchingStatementOrder = first.get().mask; - return indexMaskMatchingStatementOrder; + return first.get().mask; } public static Set getStatementOrder(TripleComponentOrder tripleComponentOrder, boolean subject, diff --git a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/HDTConverter.java b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/HDTConverter.java index 5a50b9d2..d5938c4d 100644 --- a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/HDTConverter.java +++ b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/HDTConverter.java @@ -3,7 +3,6 @@ import com.the_qa_company.qendpoint.core.dictionary.Dictionary; import com.the_qa_company.qendpoint.core.enums.RDFNodeType; import com.the_qa_company.qendpoint.core.enums.TripleComponentRole; -import com.the_qa_company.qendpoint.core.exceptions.NotImplementedException; import com.the_qa_company.qendpoint.core.hdt.HDT; import com.the_qa_company.qendpoint.model.HDTValue; import com.the_qa_company.qendpoint.model.SimpleBNodeHDT; @@ -17,9 +16,6 @@ import org.eclipse.rdf4j.model.ValueFactory; import org.eclipse.rdf4j.model.impl.SimpleValueFactory; -import java.util.Arrays; -import java.util.Objects; - // there are 4 types of resources: // resources coming from outside, // HDT IDs @@ -49,11 +45,11 @@ public long subjectToID(Resource subj) { long id = hdtval.getHDTId(); return switch (hdtval.getHDTPosition()) { - case SimpleIRIHDT.SUBJECT_POS, SimpleIRIHDT.SHARED_POS -> id; - case SimpleIRIHDT.PREDICATE_POS, SimpleIRIHDT.GRAPH_POS -> - hdt.getDictionary().stringToId(subj.toString(), TripleComponentRole.SUBJECT); - case SimpleIRIHDT.OBJECT_POS -> -1; // not shared - default -> throw new IllegalArgumentException("Invalid HDT position: " + hdtval.getHDTPosition()); + case SimpleIRIHDT.SUBJECT_POS, SimpleIRIHDT.SHARED_POS -> id; + case SimpleIRIHDT.PREDICATE_POS, SimpleIRIHDT.GRAPH_POS -> + hdt.getDictionary().stringToId(subj.toString(), TripleComponentRole.SUBJECT); + case SimpleIRIHDT.OBJECT_POS -> -1; // not shared + default -> throw new IllegalArgumentException("Invalid HDT position: " + hdtval.getHDTPosition()); }; } @@ -79,11 +75,11 @@ public long objectToID(Value obj) { long id = hdtval.getHDTId(); return switch (hdtval.getHDTPosition()) { - case SimpleIRIHDT.OBJECT_POS, SimpleIRIHDT.SHARED_POS -> id; - case SimpleIRIHDT.PREDICATE_POS, SimpleIRIHDT.GRAPH_POS -> - hdt.getDictionary().stringToId(obj.toString(), TripleComponentRole.OBJECT); - case SimpleIRIHDT.SUBJECT_POS -> -1; // not shared - default -> throw new IllegalArgumentException("Invalid HDT position: " + hdtval.getHDTPosition()); + case SimpleIRIHDT.OBJECT_POS, SimpleIRIHDT.SHARED_POS -> id; + case SimpleIRIHDT.PREDICATE_POS, SimpleIRIHDT.GRAPH_POS -> + hdt.getDictionary().stringToId(obj.toString(), TripleComponentRole.OBJECT); + case SimpleIRIHDT.SUBJECT_POS -> -1; // not shared + default -> throw new IllegalArgumentException("Invalid HDT position: " + hdtval.getHDTPosition()); }; } diff --git a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/HDTProps.java b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/HDTProps.java index 84230c88..315b824f 100644 --- a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/HDTProps.java +++ b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/HDTProps.java @@ -34,8 +34,7 @@ public HDTProps(HDT hdt) { // if the dictionay is spliting the objects to sections - we just have // to look in the // NO_DATATYPE section for the blank nodes range - if (hdt.getDictionary() instanceof MultipleSectionDictionary) { - MultipleSectionDictionary dictionary = (MultipleSectionDictionary) hdt.getDictionary(); + if (hdt.getDictionary() instanceof MultipleSectionDictionary dictionary) { start = dictionary.getDataTypeRange("NO_DATATYPE").getKey(); end = dictionary.getDataTypeRange("NO_DATATYPE").getValue(); if (end == 0) { @@ -82,9 +81,8 @@ public HDTProps(HDT hdt) { } // check if this hdt has a default graph - if (hdt.getDictionary().supportGraphs() - && hdt.getDictionary().getNgraphs() > 0 - && hdt.getDictionary().idToString(1, TripleComponentRole.GRAPH).isEmpty()) { + if (hdt.getDictionary().supportGraphs() && hdt.getDictionary().getNgraphs() > 0 + && hdt.getDictionary().idToString(1, TripleComponentRole.GRAPH).isEmpty()) { this.defaultGraph = 1; } else { this.defaultGraph = -1; diff --git a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/MergeRunnable.java b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/MergeRunnable.java index 2d11b0d5..005b75ea 100644 --- a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/MergeRunnable.java +++ b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/store/MergeRunnable.java @@ -298,7 +298,7 @@ public void run() { e.printStackTrace(); } finally { if (MergeRunnableStopPoint.debug) { - //MergeRunnableStopPoint.unlockAll(); + // MergeRunnableStopPoint.unlockAll(); debugLock.release(); } } @@ -904,8 +904,8 @@ private void createHDTDump(String rdfInput, String hdtOutput) throws IOException oopt.setOverride(HDTOptionsKeys.LOADER_DISK_LOCATION_KEY, location.resolve("gen")); oopt.setOverride(HDTOptionsKeys.LOADER_DISK_FUTURE_HDT_LOCATION_KEY, location.resolve("wip.hdt")); try { - try (HDT hdt = HDTManager.generateHDT(new File(rdfInput).getAbsolutePath(), baseURI, RDFNotation.guess(rdfInput), - oopt, null)) { + try (HDT hdt = HDTManager.generateHDT(new File(rdfInput).getAbsolutePath(), baseURI, + RDFNotation.guess(rdfInput), oopt, null)) { logger.info("File converted in: " + sw.stopAndShow()); hdt.saveToHDT(hdtOutput, null); logger.info("HDT saved to file in: " + sw.stopAndShow()); @@ -948,11 +948,10 @@ private void writeTempFile(RepositoryConnection connection, String file, boolean Resource newCtxIRI = this.endpoint.getHdtConverter().rdf4jToHdtIDcontext(stm.getContext()); newCtxIRI = this.endpoint.getHdtConverter().subjectHdtResourceToResource(newCtxIRI); - stmConverted = this.endpoint.getValueFactory().createStatement( - newSubjIRI, newPredIRI, newObjIRI, newCtxIRI); + stmConverted = this.endpoint.getValueFactory().createStatement(newSubjIRI, newPredIRI, newObjIRI, + newCtxIRI); } else { - stmConverted = this.endpoint.getValueFactory().createStatement( - newSubjIRI, newPredIRI, newObjIRI); + stmConverted = this.endpoint.getValueFactory().createStatement(newSubjIRI, newPredIRI, newObjIRI); } writer.handleStatement(stmConverted); diff --git a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/utils/BinarySearch.java b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/utils/BinarySearch.java index e83e14cf..7fea57f1 100644 --- a/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/utils/BinarySearch.java +++ b/qendpoint-store/src/main/java/com/the_qa_company/qendpoint/utils/BinarySearch.java @@ -61,7 +61,7 @@ public static long last(Dictionary dictionary, long low, long high, long n, Stri c = COMPARATOR.compare(string, s.isEmpty() ? "" : s.subSequence(0, 1)); } String s = dictionary.idToString(mid, role).toString(); - int c2 = COMPARATOR.compare(string, s.isEmpty() ? "": s.subSequence(0, 1)); + int c2 = COMPARATOR.compare(string, s.isEmpty() ? "" : s.subSequence(0, 1)); // System.out.println("c"+c); // System.out.println("c2 "+c2); if ((mid == n || c != 0) && c2 == 0) diff --git a/qendpoint-store/src/test/java/com/the_qa_company/qendpoint/store/ComplianceTest.java b/qendpoint-store/src/test/java/com/the_qa_company/qendpoint/store/ComplianceTest.java index 7c0d3565..30c832c2 100644 --- a/qendpoint-store/src/test/java/com/the_qa_company/qendpoint/store/ComplianceTest.java +++ b/qendpoint-store/src/test/java/com/the_qa_company/qendpoint/store/ComplianceTest.java @@ -14,7 +14,6 @@ import org.eclipse.rdf4j.repository.sail.SailRepository; import org.eclipse.rdf4j.testsuite.query.parser.sparql.manifest.SPARQL11QueryComplianceTest; import org.eclipse.rdf4j.testsuite.query.parser.sparql.manifest.SPARQL11UpdateComplianceTest; -import org.junit.Assert; import org.junit.Rule; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DynamicTest; @@ -46,7 +45,8 @@ public EndpointMultIndexSPARQL11QueryComplianceTest() { List testToIgnore = new ArrayList<>(); // @todo these tests are failing and should not, they are skipped so // that we can be sure that we see when - // currently passing tests are not failing. Many of these tests are not + // currently passing tests are not failing. Many of these tests are + // not // so problematic since we do not support // named graphs anyway testToIgnore.add("constructwhere02 - CONSTRUCT WHERE"); @@ -78,7 +78,7 @@ public EndpointMultIndexSPARQL11QueryComplianceTest() { @Override protected void testParameterListener(String displayName, String testURI, String name, String queryFileURL, - String resultFileURL, Dataset dataset, boolean ordered, boolean laxCardinality) { + String resultFileURL, Dataset dataset, boolean ordered, boolean laxCardinality) { try { setUpHDT(dataset); } catch (IOException | ParserException | NotFoundException e) { @@ -154,8 +154,8 @@ private void setUpHDT(Dataset dataset) throws IOException, ParserException, NotF HDTOptions spec = HDTOptions.of(); - hdt = HDTManager.generateHDT(file.getAbsolutePath(), "http://www.example.org/", RDFNotation.guess(file), spec, - null); + hdt = HDTManager.generateHDT(file.getAbsolutePath(), "http://www.example.org/", RDFNotation.guess(file), + spec, null); assert hdt != null; hdt.search("", "", "").forEachRemaining(System.out::println); } @@ -168,7 +168,8 @@ public EndpointMultIndexSPARQL11UpdateComplianceTest() { List testToIgnore = new ArrayList<>(); // @todo these tests are failing and should not, they are skipped so // that we can be sure that we see when - // currently passing tests are not failing. Many of these tests are not + // currently passing tests are not failing. Many of these tests are + // not // so problematic since we do not support // named graphs anyway testToIgnore.add("DELETE INSERT 1b"); @@ -194,8 +195,8 @@ protected Repository newRepository() throws Exception { hdt.saveToHDT(fileName, null); } - EndpointStore endpoint = new EndpointStore(hdtStore.getAbsolutePath() + "/", EndpointStoreTest.HDT_INDEX_NAME, - spec, nativeStore.getAbsolutePath() + "/", true) { + EndpointStore endpoint = new EndpointStore(hdtStore.getAbsolutePath() + "/", + EndpointStoreTest.HDT_INDEX_NAME, spec, nativeStore.getAbsolutePath() + "/", true) { @Override public HDT loadIndex() throws IOException { @@ -222,8 +223,6 @@ public HDT loadIndex() throws IOException { // endpoint.setThreshold(2); return new SailRepository(endpoint); - // return new DatasetRepository(new SailRepository(new - // NativeStore(tempDir.newFolder(), "spoc"))); } } @@ -238,7 +237,8 @@ public EndpointSPARQL11QueryComplianceTest() { // @todo these tests are failing and should not, they are // skipped so // that we can be sure that we see when - // currently passing tests are not failing. Many of these tests + // currently passing tests are not failing. Many of these + // tests // are not // so problematic since we do not support // named graphs anyway @@ -258,7 +258,7 @@ public EndpointSPARQL11QueryComplianceTest() { @Override protected void testParameterListener(String displayName, String testURI, String name, String queryFileURL, - String resultFileURL, Dataset dataset, boolean ordered, boolean laxCardinality) { + String resultFileURL, Dataset dataset, boolean ordered, boolean laxCardinality) { try { setUpHDT(dataset); } catch (IOException | ParserException | NotFoundException e) { @@ -317,8 +317,8 @@ private void setUpHDT(Dataset dataset) throws IOException, ParserException, NotF HDTOptions spec = HDTOptions.of(); - hdt = HDTManager.generateHDT(file.getAbsolutePath(), "http://www.example.org/", RDFNotation.guess(file), spec, - null); + hdt = HDTManager.generateHDT(file.getAbsolutePath(), "http://www.example.org/", RDFNotation.guess(file), + spec, null); assert hdt != null; hdt.search("", "", "").forEachRemaining(System.out::println); } @@ -331,7 +331,8 @@ public EndpointSPARQL11UpdateComplianceTest() { List testToIgnore = new ArrayList<>(); // @todo these tests are failing and should not, they are skipped so // that we can be sure that we see when - // currently passing tests are not failing. Many of these tests are not + // currently passing tests are not failing. Many of these tests are + // not // so problematic since we do not support // named graphs anyway testToIgnore.add("DELETE INSERT 1b"); @@ -355,8 +356,8 @@ protected Repository newRepository() throws Exception { hdt.saveToHDT(hdtStore.getAbsolutePath() + "/" + EndpointStoreTest.HDT_INDEX_NAME, null); } - EndpointStore endpoint = new EndpointStore(hdtStore.getAbsolutePath() + "/", EndpointStoreTest.HDT_INDEX_NAME, - spec, nativeStore.getAbsolutePath() + "/", true); + EndpointStore endpoint = new EndpointStore(hdtStore.getAbsolutePath() + "/", + EndpointStoreTest.HDT_INDEX_NAME, spec, nativeStore.getAbsolutePath() + "/", true); // endpoint.setThreshold(2); return new SailRepository(endpoint); @@ -371,7 +372,7 @@ public static class EndpointQuadSPARQL11QueryComplianceTest extends SPARQL11Quer @Override protected void testParameterListener(String displayName, String testURI, String name, String queryFileURL, - String resultFileURL, Dataset dataset, boolean ordered, boolean laxCardinality) { + String resultFileURL, Dataset dataset, boolean ordered, boolean laxCardinality) { try { setUpHDT(dataset); } catch (IOException | ParserException | NotFoundException e) { @@ -430,8 +431,8 @@ private void setUpHDT(Dataset dataset) throws IOException, ParserException, NotF HDTOptions spec = HDTOptions.of(); - hdt = HDTManager.generateHDT(file.getAbsolutePath(), "http://www.example.org/", RDFNotation.guess(file), spec, - null); + hdt = HDTManager.generateHDT(file.getAbsolutePath(), "http://www.example.org/", RDFNotation.guess(file), + spec, null); assert hdt != null; hdt.search("", "", "").forEachRemaining(System.out::println); } @@ -453,8 +454,8 @@ protected Repository newRepository() throws Exception { hdt.saveToHDT(hdtStore.getAbsolutePath() + "/" + EndpointStoreTest.HDT_INDEX_NAME, null); } - EndpointStore endpoint = new EndpointStore(hdtStore.getAbsolutePath() + "/", EndpointStoreTest.HDT_INDEX_NAME, - spec, nativeStore.getAbsolutePath() + "/", true); + EndpointStore endpoint = new EndpointStore(hdtStore.getAbsolutePath() + "/", + EndpointStoreTest.HDT_INDEX_NAME, spec, nativeStore.getAbsolutePath() + "/", true); return new SailRepository(endpoint); } @@ -465,22 +466,27 @@ protected Repository newRepository() throws Exception { public Collection multiIndexQuery() { return new EndpointMultIndexSPARQL11QueryComplianceTest().tests(); } + @TestFactory public Collection multiIndexUpdate() { return new EndpointMultIndexSPARQL11UpdateComplianceTest().getTestData(); } + @TestFactory public Collection indexQuery() { return new EndpointSPARQL11QueryComplianceTest().tests(); } + @TestFactory public Collection indexUpdate() { return new EndpointSPARQL11UpdateComplianceTest().getTestData(); } + @TestFactory public Collection quadQuery() { return new EndpointQuadSPARQL11QueryComplianceTest().tests(); } + @TestFactory public Collection quadUpdate() { return new EndpointQuadSPARQL11UpdateComplianceTest().getTestData(); diff --git a/qendpoint-store/src/test/java/com/the_qa_company/qendpoint/store/EndpointStoreGraphTest.java b/qendpoint-store/src/test/java/com/the_qa_company/qendpoint/store/EndpointStoreGraphTest.java index 655bbea1..2f8d9c6c 100644 --- a/qendpoint-store/src/test/java/com/the_qa_company/qendpoint/store/EndpointStoreGraphTest.java +++ b/qendpoint-store/src/test/java/com/the_qa_company/qendpoint/store/EndpointStoreGraphTest.java @@ -29,15 +29,14 @@ public class EndpointStoreGraphTest { @Rule public TemporaryFolder tempDir = TemporaryFolder.builder().assureDeletion().build(); - public static String posStr(int pos) { return switch (pos) { - case SimpleIRIHDT.SUBJECT_POS -> "s"; - case SimpleIRIHDT.PREDICATE_POS -> "p"; - case SimpleIRIHDT.OBJECT_POS -> "o"; - case SimpleIRIHDT.SHARED_POS -> "sh"; - case SimpleIRIHDT.GRAPH_POS -> "g"; - default -> "unk" + pos; + case SimpleIRIHDT.SUBJECT_POS -> "s"; + case SimpleIRIHDT.PREDICATE_POS -> "p"; + case SimpleIRIHDT.OBJECT_POS -> "o"; + case SimpleIRIHDT.SHARED_POS -> "sh"; + case SimpleIRIHDT.GRAPH_POS -> "g"; + default -> "unk" + pos; }; } @@ -47,8 +46,10 @@ public static String printVal(Value val) { } return val.toString(); } + public static void printStmt(Statement stmt) { - System.out.print(printVal(stmt.getSubject()) + ", " + printVal(stmt.getPredicate()) + ", " + printVal(stmt.getObject())); + System.out.print( + printVal(stmt.getSubject()) + ", " + printVal(stmt.getPredicate()) + ", " + printVal(stmt.getObject())); if (stmt.getContext() != null) { System.out.println(" [" + printVal(stmt.getContext()) + "]"); } else { @@ -75,15 +76,15 @@ public void graphTest() throws IOException, InterruptedException, NotFoundExcept HDTOptionsKeys.DICTIONARY_TYPE_KEY, HDTOptionsKeys.DICTIONARY_TYPE_VALUE_MULTI_OBJECTS_LANG_QUAD // temp dict , HDTOptionsKeys.TEMP_DICTIONARY_IMPL_KEY, HDTOptionsKeys.TEMP_DICTIONARY_IMPL_VALUE_HASH_QUAD - // merge join? - //, EndpointStore.OPTION_QENDPOINT_MERGE_JOIN, false + // merge join? + // , EndpointStore.OPTION_QENDPOINT_MERGE_JOIN, false ); - SparqlRepository sparqlRepository = CompiledSail.compiler() - .withEndpointFiles(new EndpointFiles(roo.toPath())) + SparqlRepository sparqlRepository = CompiledSail.compiler().withEndpointFiles(new EndpointFiles(roo.toPath())) .withHDTSpec(spec).compileToSparqlRepository(); - EndpointStore endpointStore = (EndpointStore) ((CompiledSail) sparqlRepository.getRepository().getSail()).getSource(); + EndpointStore endpointStore = (EndpointStore) ((CompiledSail) sparqlRepository.getRepository().getSail()) + .getSource(); ValueFactory vf = sparqlRepository.getRepository().getValueFactory(); try { @@ -91,27 +92,19 @@ public void graphTest() throws IOException, InterruptedException, NotFoundExcept System.out.println("ADD"); try (SailRepositoryConnection conn = sparqlRepository.getConnection()) { conn.begin(); - conn.add(vf.createStatement( - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"), + conn.add(vf.createStatement(vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"), vf.createIRI(Utility.EXAMPLE_NAMESPACE + "o"), vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"), - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "graph") - )); - conn.add(vf.createStatement( - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"), + vf.createIRI(Utility.EXAMPLE_NAMESPACE + "graph"))); + conn.add(vf.createStatement(vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"), vf.createIRI(Utility.EXAMPLE_NAMESPACE + "o"), - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa") - )); - conn.add(vf.createStatement( - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "ss"), + vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"))); + conn.add(vf.createStatement(vf.createIRI(Utility.EXAMPLE_NAMESPACE + "ss"), vf.createIRI(Utility.EXAMPLE_NAMESPACE + "p"), - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa5") - )); - conn.add(vf.createStatement( - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "ss"), + vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa5"))); + conn.add(vf.createStatement(vf.createIRI(Utility.EXAMPLE_NAMESPACE + "ss"), vf.createIRI(Utility.EXAMPLE_NAMESPACE + "p"), - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa6") - )); + vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa6"))); conn.commit(); } } @@ -130,15 +123,18 @@ public void graphTest() throws IOException, InterruptedException, NotFoundExcept { try (SailRepositoryConnection conn = sparqlRepository.getConnection()) { System.out.println("SEARCH GRAPH"); - try (RepositoryResult st = conn.getStatements(null, null, null, false, vf.createIRI(Utility.EXAMPLE_NAMESPACE + "graph"))) { + try (RepositoryResult st = conn.getStatements(null, null, null, false, + vf.createIRI(Utility.EXAMPLE_NAMESPACE + "graph"))) { st.stream().forEach(EndpointStoreGraphTest::printStmt); } System.out.println("SEARCH NO GRAPH"); - try (RepositoryResult st = conn.getStatements(null, null, null, false, (Resource) null)) { + try (RepositoryResult st = conn.getStatements(null, null, null, false, + (Resource) null)) { st.stream().forEach(EndpointStoreGraphTest::printStmt); } System.out.println("SEARCH BOTH GRAPH"); - try (RepositoryResult st = conn.getStatements(null, null, null, false, vf.createIRI(Utility.EXAMPLE_NAMESPACE + "graph"), null)) { + try (RepositoryResult st = conn.getStatements(null, null, null, false, + vf.createIRI(Utility.EXAMPLE_NAMESPACE + "graph"), null)) { st.stream().forEach(EndpointStoreGraphTest::printStmt); } @@ -148,11 +144,9 @@ public void graphTest() throws IOException, InterruptedException, NotFoundExcept System.out.println("REM DEFAULT"); try (SailRepositoryConnection conn = sparqlRepository.getConnection()) { conn.begin(); - conn.remove( - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"), - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "o"), - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"), - (Resource) null); + conn.remove(vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"), + vf.createIRI(Utility.EXAMPLE_NAMESPACE + "o"), + vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"), (Resource) null); conn.commit(); } } @@ -168,11 +162,11 @@ public void graphTest() throws IOException, InterruptedException, NotFoundExcept System.out.println("REM GRAPH"); try (SailRepositoryConnection conn = sparqlRepository.getConnection()) { conn.begin(); - conn.remove(vf.createStatement( - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"), - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "o"), - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa") - ), vf.createIRI(Utility.EXAMPLE_NAMESPACE + "graph")); + conn.remove( + vf.createStatement(vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"), + vf.createIRI(Utility.EXAMPLE_NAMESPACE + "o"), + vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa")), + vf.createIRI(Utility.EXAMPLE_NAMESPACE + "graph")); conn.commit(); } } @@ -207,12 +201,10 @@ public void graphTest() throws IOException, InterruptedException, NotFoundExcept { try (SailRepositoryConnection conn = sparqlRepository.getConnection()) { conn.begin(); - conn.add(vf.createStatement( - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"), + conn.add(vf.createStatement(vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"), vf.createIRI(Utility.EXAMPLE_NAMESPACE + "o"), vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa2"), - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "graph2") - )); + vf.createIRI(Utility.EXAMPLE_NAMESPACE + "graph2"))); conn.commit(); } } @@ -229,12 +221,10 @@ public void graphTest() throws IOException, InterruptedException, NotFoundExcept { try (SailRepositoryConnection conn = sparqlRepository.getConnection()) { conn.begin(); - conn.add(vf.createStatement( - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"), + conn.add(vf.createStatement(vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"), vf.createIRI(Utility.EXAMPLE_NAMESPACE + "o"), vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa3"), - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "graph2") - )); + vf.createIRI(Utility.EXAMPLE_NAMESPACE + "graph2"))); conn.commit(); } } @@ -246,32 +236,26 @@ public void graphTest() throws IOException, InterruptedException, NotFoundExcept { try (SailRepositoryConnection conn = sparqlRepository.getConnection()) { conn.begin(); - conn.add(vf.createStatement( - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"), + conn.add(vf.createStatement(vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"), vf.createIRI(Utility.EXAMPLE_NAMESPACE + "o"), vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa4"), - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "graph2") - )); + vf.createIRI(Utility.EXAMPLE_NAMESPACE + "graph2"))); conn.commit(); } try (SailRepositoryConnection conn = sparqlRepository.getConnection()) { conn.begin(); - conn.add(vf.createStatement( - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"), + conn.add(vf.createStatement(vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa"), vf.createIRI(Utility.EXAMPLE_NAMESPACE + "o"), vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa3"), - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "graph2") - )); + vf.createIRI(Utility.EXAMPLE_NAMESPACE + "graph2"))); conn.commit(); } System.out.println("REM 6"); try (SailRepositoryConnection conn = sparqlRepository.getConnection()) { conn.begin(); - conn.remove( - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "ss"), + conn.remove(vf.createIRI(Utility.EXAMPLE_NAMESPACE + "ss"), vf.createIRI(Utility.EXAMPLE_NAMESPACE + "p"), - vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa6"), - (Resource) null); + vf.createIRI(Utility.EXAMPLE_NAMESPACE + "aa6"), (Resource) null); conn.commit(); } } diff --git a/qendpoint-store/src/test/java/com/the_qa_company/qendpoint/store/MergeRestartTest.java b/qendpoint-store/src/test/java/com/the_qa_company/qendpoint/store/MergeRestartTest.java index 26768790..d7c4ba3e 100644 --- a/qendpoint-store/src/test/java/com/the_qa_company/qendpoint/store/MergeRestartTest.java +++ b/qendpoint-store/src/test/java/com/the_qa_company/qendpoint/store/MergeRestartTest.java @@ -63,6 +63,7 @@ public class MergeRestartTest { public static Collection params() { return List.of(true, false); } + private static final Logger logger = LoggerFactory.getLogger(MergeRestartTest.class); private static final File HALT_TEST_DIR = new File("tests", "halt_test_dir"); @Rule @@ -150,15 +151,13 @@ private void lockIfAfter(MergeRunnableStopPoint point, MergeRunnableStopPoint cu } } - private void mergeRestartTest1(MergeRunnableStopPoint stopPoint) - throws IOException, InterruptedException { + private void mergeRestartTest1(MergeRunnableStopPoint stopPoint) throws IOException, InterruptedException { try (Closer closer = Closer.of()) { mergeRestartTest1(stopPoint, MergeRestartTest.HALT_TEST_DIR, closer); } } - private void mergeRestartTest2(MergeRunnableStopPoint stopPoint) - throws IOException, InterruptedException { + private void mergeRestartTest2(MergeRunnableStopPoint stopPoint) throws IOException, InterruptedException { try (Closer closer = Closer.of()) { mergeRestartTest2(stopPoint, MergeRestartTest.HALT_TEST_DIR, closer); } @@ -431,7 +430,8 @@ private void mergeRestartTest2(MergeRunnableStopPoint point, File root, Closer c EndpointStoreTest.HDT_INDEX_NAME, spec, nativeStore.getAbsolutePath() + File.separator, false); SailRepository endpointStore2 = new SailRepository(store2); - closer.with((Closeable) endpointStore2::shutDown, (Closeable) store2::deleteNativeLocks, (Closeable) MergeRunnableStopPoint::unlockAll); + closer.with((Closeable) endpointStore2::shutDown, (Closeable) store2::deleteNativeLocks, + (Closeable) MergeRunnableStopPoint::unlockAll); // a merge should be triggered // test at each step if the count is the same @@ -505,7 +505,7 @@ public void mergeRestartTest(MergeRunnableStopPoint stopPoint) throws IOExceptio // start the second phase mergeRestartTest2(stopPoint, root2, closer); - } catch (Throwable t) { + } catch (Throwable t) { try { FileUtils.deleteDirectory(testRoot); } catch (IOException e) { @@ -738,7 +738,7 @@ public void halt2MergeRestartMergeEndAfterSleepTest() throws IOException, Interr /** * print the HDT and the bitmap (if store not null) * - * @param hdt the hdt to print + * @param hdt the hdt to print */ public static void printHDT(HDT hdt) { IteratorTripleString it; @@ -888,7 +888,8 @@ private void executeTestRemoveHDT(File out, SailRepository repo, int id, int cou connection.remove(stm); }); writeInfoCount(out, count); - try (OutputStream buff = new BufferedOutputStream(new FileOutputStream(out.getAbsolutePath() + ".delta", true))) { + try (OutputStream buff = new BufferedOutputStream( + new FileOutputStream(out.getAbsolutePath() + ".delta", true))) { buff.write(("REM HDT " + id + " / " + count + "\n").getBytes(StandardCharsets.UTF_8)); } @@ -912,7 +913,8 @@ private void executeTestRemoveRDF(File out, SailRepository repo, int id, int cou connection.remove(stm); }); writeInfoCount(out, count); - try (OutputStream buff = new BufferedOutputStream(new FileOutputStream(out.getAbsolutePath() + ".delta", true))) { + try (OutputStream buff = new BufferedOutputStream( + new FileOutputStream(out.getAbsolutePath() + ".delta", true))) { buff.write(("REM RDF " + id + " / " + count + "\n").getBytes(StandardCharsets.UTF_8)); } } @@ -935,7 +937,8 @@ private void executeTestAddRDF(File out, SailRepository repo, int id, int count) connection.add(stm); }); writeInfoCount(out, count); - try (OutputStream buff = new BufferedOutputStream(new FileOutputStream(out.getAbsolutePath() + ".delta", true))) { + try (OutputStream buff = new BufferedOutputStream( + new FileOutputStream(out.getAbsolutePath() + ".delta", true))) { buff.write(("ADD RDF " + id + " / " + count + "\n").getBytes(StandardCharsets.UTF_8)); } } @@ -959,7 +962,8 @@ private void executeTestAddHDT(File out, SailRepository repo, int id, int count) connection.add(stm); }); writeInfoCount(out, count); - try (OutputStream buff = new BufferedOutputStream(new FileOutputStream(out.getAbsolutePath() + ".delta", true))) { + try (OutputStream buff = new BufferedOutputStream( + new FileOutputStream(out.getAbsolutePath() + ".delta", true))) { buff.write(("ADD HDT " + id + " / " + count + "\n").getBytes(StandardCharsets.UTF_8)); } } @@ -979,61 +983,61 @@ private void executeTestCount(File out, SailRepository repo, EndpointStore store System.out.println("values:"); if (count != excepted) { - try (RepositoryResult query = connection.getStatements(null, null, null, false)) { - query.forEach(EndpointStoreGraphTest::printStmt); - } - if (store != null) { - System.out.println("curr ns: " + (store.switchStore ? "2" : "1")); - System.out.println("ns1:"); - Consumer printer = stmt -> { - HDTConverter converter = store.getHdtConverter(); - EndpointStoreGraphTest.printStmt(converter.rdf4ToHdt(stmt)); - }; - try (NotifyingSailConnection conn = store.getNativeStoreA().getConnection()) { - try (CloseableIteration it = conn.getStatements(null, null, null, false)) { - it.forEachRemaining(printer); - } + try (RepositoryResult query = connection.getStatements(null, null, null, false)) { + query.forEach(EndpointStoreGraphTest::printStmt); } - System.out.println("ns2:"); - try (NotifyingSailConnection conn = store.getNativeStoreB().getConnection()) { - try (CloseableIteration it = conn.getStatements(null, null, null, false)) { - it.forEachRemaining(printer); + if (store != null) { + System.out.println("curr ns: " + (store.switchStore ? "2" : "1")); + System.out.println("ns1:"); + Consumer printer = stmt -> { + HDTConverter converter = store.getHdtConverter(); + EndpointStoreGraphTest.printStmt(converter.rdf4ToHdt(stmt)); + }; + try (NotifyingSailConnection conn = store.getNativeStoreA().getConnection()) { + try (CloseableIteration it = conn.getStatements(null, null, null, false)) { + it.forEachRemaining(printer); + } } - } - System.out.println("hdt:"); - try { - store.getHdt().searchAll().forEachRemaining(System.out::println); - } catch (NotFoundException e) { - throw new RuntimeException(e); - } - System.out.println("bitmaps:"); - - long size = store.getHdt().getTriples().getNumberOfElements(); - long graphs = store.getGraphsCount(); - for (int i = 0; i < store.getDeleteBitMaps().length; i++) { - TripleComponentOrder order = TripleComponentOrder.values()[i]; - MultiLayerBitmapWrapper.MultiLayerModBitmapWrapper bm = store.getDeleteBitMaps()[i]; - if (bm == null) { - continue; + System.out.println("ns2:"); + try (NotifyingSailConnection conn = store.getNativeStoreB().getConnection()) { + try (CloseableIteration it = conn.getStatements(null, null, null, false)) { + it.forEachRemaining(printer); + } + } + System.out.println("hdt:"); + try { + store.getHdt().searchAll().forEachRemaining(System.out::println); + } catch (NotFoundException e) { + throw new RuntimeException(e); } + System.out.println("bitmaps:"); + + long size = store.getHdt().getTriples().getNumberOfElements(); + long graphs = store.getGraphsCount(); + for (int i = 0; i < store.getDeleteBitMaps().length; i++) { + TripleComponentOrder order = TripleComponentOrder.values()[i]; + MultiLayerBitmapWrapper.MultiLayerModBitmapWrapper bm = store.getDeleteBitMaps()[i]; + if (bm == null) { + continue; + } - System.out.println(order); - for (int g = 0; g < graphs; g++) { - System.out.print("g" + (g + 1) + ": "); - for (long t = 0; t < size; t++) { - System.out.print(bm.access(g, t) ? "1" : "0"); + System.out.println(order); + for (int g = 0; g < graphs; g++) { + System.out.print("g" + (g + 1) + ": "); + for (long t = 0; t < size; t++) { + System.out.print(bm.access(g, t) ? "1" : "0"); + } + System.out.println(); } - System.out.println(); } } - } - System.out.println("operations:"); - try { - System.out.println(Files.readString(Path.of(out.getAbsolutePath() + ".delta"))); - } catch (IOException e) { - throw new RuntimeException(e); - } + System.out.println("operations:"); + try { + System.out.println(Files.readString(Path.of(out.getAbsolutePath() + ".delta"))); + } catch (IOException e) { + throw new RuntimeException(e); + } fail(format("count:%d != excepted:%d : Invalid test count", count, excepted)); } }); diff --git a/qendpoint-store/src/test/java/com/the_qa_company/qendpoint/store/experimental/ExperimentalQEndpointSPARQL11ComplianceUpdateTest.java b/qendpoint-store/src/test/java/com/the_qa_company/qendpoint/store/experimental/ExperimentalQEndpointSPARQL11ComplianceUpdateTest.java index 3bb5ab02..266aa6a4 100644 --- a/qendpoint-store/src/test/java/com/the_qa_company/qendpoint/store/experimental/ExperimentalQEndpointSPARQL11ComplianceUpdateTest.java +++ b/qendpoint-store/src/test/java/com/the_qa_company/qendpoint/store/experimental/ExperimentalQEndpointSPARQL11ComplianceUpdateTest.java @@ -16,38 +16,132 @@ import java.util.List; @Ignore("later") -public class ExperimentalQEndpointSPARQL11ComplianceUpdateTest { /* extends SPARQL11UpdateComplianceTest { - - // Set this to true to print the call to the store when doing the compliance tests - private static final boolean PRINT_CALLS = false; - - // Set this to false to enable the graph tests - private static final boolean DISABLE_GRAPH_TESTS = true; - - @TempDir - public Path tempDir; - - public ExperimentalQEndpointSPARQL11ComplianceUpdateTest() { - if (DISABLE_GRAPH_TESTS) { - this.setIgnoredTests(new ArrayList<>(List.of("INSERT 03", "INSERT 04", "INSERT USING 01", - "DELETE INSERT 1b", "DELETE INSERT 1c", "INSERT same bnode twice", "CLEAR NAMED", "DROP NAMED", - "DROP GRAPH", "DROP DEFAULT", "CLEAR GRAPH", "CLEAR DEFAULT", "COPY 1", "COPY 3", "COPY 6", - "MOVE 1", "MOVE 3", "MOVE 6", "Graph-specific DELETE DATA 1", "Graph-specific DELETE DATA 2", - "Graph-specific DELETE 1", "Graph-specific DELETE 1 (WITH)", "Graph-specific DELETE 1 (USING)", - "Simple DELETE 1 (USING)", "Simple DELETE 2 (WITH)", "Simple DELETE 4 (WITH)"))); - } - } - - @Override - protected Repository newRepository() throws Exception { - HDTOptions spec = HDTOptions.of(HDTOptionsKeys.DICTIONARY_TYPE_KEY, - HDTOptionsKeys.DICTIONARY_TYPE_VALUE_MULTI_OBJECTS_LANG); - ExperimentalQEndpointSail sail = new ExperimentalQEndpointSail(tempDir, spec); - - if (PRINT_CALLS) { - return Utility.convertToDumpRepository(new SailRepository(Utility.convertToDumpSail(sail))); - } - return new SailRepository(sail); - } -*/ +public class ExperimentalQEndpointSPARQL11ComplianceUpdateTest { /* + * extends + * SPARQL11UpdateComplianceTest + * { // Set + * this to + * true to + * print the + * call to + * the store + * when + * doing the + * compliance + * tests + * private + * static + * final + * boolean + * PRINT_CALLS + * = false; + * // Set + * this to + * false to + * enable + * the graph + * tests + * private + * static + * final + * boolean + * DISABLE_GRAPH_TESTS + * = true; + * @TempDir + * public + * Path + * tempDir; + * public + * ExperimentalQEndpointSPARQL11ComplianceUpdateTest + * () { if + * (DISABLE_GRAPH_TESTS) + * { this. + * setIgnoredTests + * (new + * ArrayList + * <>(List. + * of("INSERT 03" + * , + * "INSERT 04" + * , + * "INSERT USING 01" + * , + * "DELETE INSERT 1b" + * , + * "DELETE INSERT 1c" + * , + * "INSERT same bnode twice" + * , + * "CLEAR NAMED" + * , + * "DROP NAMED" + * , + * "DROP GRAPH" + * , + * "DROP DEFAULT" + * , + * "CLEAR GRAPH" + * , + * "CLEAR DEFAULT" + * , + * "COPY 1", + * "COPY 3", + * "COPY 6", + * "MOVE 1", + * "MOVE 3", + * "MOVE 6", + * "Graph-specific DELETE DATA 1" + * , + * "Graph-specific DELETE DATA 2" + * , + * "Graph-specific DELETE 1" + * , + * "Graph-specific DELETE 1 (WITH)" + * , + * "Graph-specific DELETE 1 (USING)" + * , + * "Simple DELETE 1 (USING)" + * , + * "Simple DELETE 2 (WITH)" + * , + * "Simple DELETE 4 (WITH)" + * ))); } } + * @Override + * protected + * Repository + * newRepository + * () throws + * Exception + * { + * HDTOptions + * spec = + * HDTOptions + * .of( + * HDTOptionsKeys + * . + * DICTIONARY_TYPE_KEY, + * HDTOptionsKeys + * . + * DICTIONARY_TYPE_VALUE_MULTI_OBJECTS_LANG + * ); + * ExperimentalQEndpointSail + * sail = + * new + * ExperimentalQEndpointSail + * (tempDir, + * spec); if + * (PRINT_CALLS) + * { return + * Utility. + * convertToDumpRepository + * (new + * SailRepository + * (Utility. + * convertToDumpSail + * (sail))); + * } return + * new + * SailRepository + * (sail); } + */ }