Search in sources :

Example 1 with UpdateMetricsResponseHandler

use of org.wikidata.query.rdf.tool.rdf.client.UpdateMetricsResponseHandler in project wikidata-query-rdf by wikimedia.

the class RdfRepositoryUpdaterUnitTest method testReconcile.

@Test
public void testReconcile() {
    entitiesToReconcile.put("Q123", Arrays.asList(statement("http://acme.test/entity/Q123", "http://actme.test/prop/direct/P123", "uri:something"), statement("http://acme.test/entity/Q123", "http://actme.test/prop/P123", "http://acme.test/entity/statement/Q123-S-123"), statement("http://acme.test/entity/statement/Q123-S-123", "http://actme.test/property/P123", "http://acme.test/property/statement/Q123"), statement("https://oc.wikipedia.org/Affachade", "http://actme.test/property/P123", "http://acme.test/entity/Q123")));
    ConsumerPatch patch = new ConsumerPatch(statements(), statements(), statements(), statements(), entityIdsToDelete, entitiesToReconcile);
    RdfRepositoryUpdater rdfRepositoryUpdater = new RdfRepositoryUpdater(client, urisScheme);
    UpdateMetricsResponseHandler handler = new UpdateMetricsResponseHandler(false, false, true);
    CollectedUpdateMetrics metrics = new CollectedUpdateMetrics();
    metrics.setMutationCount(10);
    when(client.update(anyString(), any())).thenReturn(metrics);
    RDFPatchResult result = rdfRepositoryUpdater.applyPatch(patch, avgEventTime);
    ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
    verify(client, times(1)).update(captor.capture(), any());
    assertThat(result.getReconciliationMutations()).isEqualTo(10);
    assertThat(captor.getValue()).isEqualTo(reconciliationQueryString);
}
Also used : UpdateMetricsResponseHandler(org.wikidata.query.rdf.tool.rdf.client.UpdateMetricsResponseHandler) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 2 with UpdateMetricsResponseHandler

use of org.wikidata.query.rdf.tool.rdf.client.UpdateMetricsResponseHandler in project wikidata-query-rdf by wikimedia.

the class RdfRepository method sendUpdateBatch.

private CollectedUpdateMetrics sendUpdateBatch(Set<String> entityIds, List<Statement> insertStatements, ClassifiedStatements classifiedStatements, Set<String> valueSet, Set<String> refSet, boolean verifyResult, boolean withTimestamp) {
    log.debug("Processing {} IDs and {} statements", entityIds.size(), insertStatements.size());
    String query = multiSyncUpdateQueryFactory.buildQuery(entityIds, insertStatements, classifiedStatements, valueSet, refSet, fetchLexemeSubIds(entityIds), withTimestamp ? Optional.of(Instant.now()) : Optional.empty());
    log.debug("Sending query {} bytes", query.length());
    long start = System.nanoTime();
    CollectedUpdateMetrics collectedUpdateMetrics = rdfClient.update(query, new UpdateMetricsResponseHandler(!refSet.isEmpty(), !valueSet.isEmpty(), withTimestamp));
    log.debug("Update query took {} nanos and modified {} statements", System.nanoTime() - start, collectedUpdateMetrics.getMutationCount());
    if (verifyResult) {
        try {
            verifyStatements(entityIds, insertStatements);
        } catch (QueryEvaluationException e) {
            throw new FatalException("Can't load verify results: " + e, e);
        }
    }
    return collectedUpdateMetrics;
}
Also used : QueryEvaluationException(org.openrdf.query.QueryEvaluationException) FatalException(org.wikidata.query.rdf.tool.exception.FatalException) UpdateMetricsResponseHandler(org.wikidata.query.rdf.tool.rdf.client.UpdateMetricsResponseHandler)

Aggregations

UpdateMetricsResponseHandler (org.wikidata.query.rdf.tool.rdf.client.UpdateMetricsResponseHandler)2 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)1 FatalException (org.wikidata.query.rdf.tool.exception.FatalException)1