Search in sources :

Example 6 with RecentChangeResponse

use of org.wikidata.query.rdf.tool.wikibase.RecentChangeResponse in project wikidata-query-rdf by wikimedia.

the class RecentChangesPollerUnitTest method noBackoffForOld.

/**
 * Verify that no backoff happens for old changes.
 * @throws RetryableException
 */
public void noBackoffForOld() throws RetryableException {
    Instant startTime = Instant.now().minus(1, ChronoUnit.DAYS);
    RecentChangesPoller poller = new RecentChangesPoller(repository, startTime, 10, new MetricRegistry());
    WikibaseApiError error = null;
    Continue aContinue = null;
    Query query = new Query(emptyList());
    RecentChangeResponse result = new RecentChangeResponse(error, aContinue, query);
    ArgumentCaptor<Instant> argument = ArgumentCaptor.forClass(Instant.class);
    when(repository.fetchRecentChanges(argument.capture(), any(), eq(batchSize))).thenReturn(result);
    when(repository.isEntityNamespace(0)).thenReturn(true);
    when(repository.isValidEntity(any(String.class))).thenReturn(true);
    Batch batch = poller.firstBatch();
    assertThat(argument.getValue()).isEqualTo(startTime);
}
Also used : WikibaseApiError(org.wikidata.query.rdf.tool.wikibase.WikibaseApiError) Query(org.wikidata.query.rdf.tool.wikibase.RecentChangeResponse.Query) Batch(org.wikidata.query.rdf.tool.change.RecentChangesPoller.Batch) Instant(java.time.Instant) MetricRegistry(com.codahale.metrics.MetricRegistry) Continue(org.wikidata.query.rdf.tool.wikibase.Continue) RecentChangeResponse(org.wikidata.query.rdf.tool.wikibase.RecentChangeResponse)

Example 7 with RecentChangeResponse

use of org.wikidata.query.rdf.tool.wikibase.RecentChangeResponse in project wikidata-query-rdf by wikimedia.

the class RecentChangesPollerUnitTest method delete.

/**
 * Check that delete is processed.
 * @throws RetryableException
 */
@Test
@SuppressWarnings("unchecked")
public void delete() throws RetryableException {
    // Use old date to remove backoff
    Instant startTime = Instant.now().minus(10, ChronoUnit.DAYS);
    // Build a result from wikibase with duplicate recent changes
    WikibaseApiError error = null;
    Continue aContinue = null;
    List<RecentChange> recentChanges = new ArrayList<>();
    recentChanges.add(new RecentChange(0L, "Q424242", Instant.now(), 0L, 42L, "log"));
    recentChanges.add(new RecentChange(0L, "Q424242", Instant.now(), 7L, 45L, "edit"));
    Query query = new Query(recentChanges);
    RecentChangeResponse result = new RecentChangeResponse(error, aContinue, query);
    firstBatchReturns(startTime, result);
    RecentChangesPoller poller = new RecentChangesPoller(repository, startTime, batchSize, new MetricRegistry());
    Batch batch = poller.firstBatch();
    List<Change> changes = batch.changes();
    assertThat(changes).hasSize(1);
    assertThat(changes.get(0).entityId()).isEqualTo("Q424242");
    assertThat(changes.get(0).offset()).isEqualTo(42L);
    assertThat(changes.get(0).revision()).isEqualTo(-1L);
}
Also used : Query(org.wikidata.query.rdf.tool.wikibase.RecentChangeResponse.Query) Instant(java.time.Instant) MetricRegistry(com.codahale.metrics.MetricRegistry) ArrayList(java.util.ArrayList) RecentChange(org.wikidata.query.rdf.tool.wikibase.RecentChangeResponse.RecentChange) Continue(org.wikidata.query.rdf.tool.wikibase.Continue) WikibaseApiError(org.wikidata.query.rdf.tool.wikibase.WikibaseApiError) RecentChange(org.wikidata.query.rdf.tool.wikibase.RecentChangeResponse.RecentChange) Batch(org.wikidata.query.rdf.tool.change.RecentChangesPoller.Batch) RecentChangeResponse(org.wikidata.query.rdf.tool.wikibase.RecentChangeResponse) Test(org.junit.Test)

Example 8 with RecentChangeResponse

use of org.wikidata.query.rdf.tool.wikibase.RecentChangeResponse in project wikidata-query-rdf by wikimedia.

the class RecentChangesPoller method fetchRecentChanges.

/**
 * Fetch recent changes from Wikibase.
 * If we're close to current time, we back off a bit from last timestamp,
 * and fetch by timestamp. If it's back in the past, we fetch by continuation.
 *
 * @throws RetryableException on fetch failure
 */
private RecentChangeResponse fetchRecentChanges(Instant lastNextStartTime, Batch lastBatch) throws RetryableException {
    try (Context timerContext = recentChangesTimer.time()) {
        RecentChangeResponse recentChanges = doFetchRecentChanges(lastNextStartTime, lastBatch);
        recentChangesCounter.inc(recentChanges.getQuery().getRecentChanges().size());
        return recentChanges;
    }
}
Also used : Context(com.codahale.metrics.Timer.Context) RecentChangeResponse(org.wikidata.query.rdf.tool.wikibase.RecentChangeResponse)

Aggregations

RecentChangeResponse (org.wikidata.query.rdf.tool.wikibase.RecentChangeResponse)8 Instant (java.time.Instant)7 Continue (org.wikidata.query.rdf.tool.wikibase.Continue)7 MetricRegistry (com.codahale.metrics.MetricRegistry)6 Batch (org.wikidata.query.rdf.tool.change.RecentChangesPoller.Batch)6 Query (org.wikidata.query.rdf.tool.wikibase.RecentChangeResponse.Query)6 RecentChange (org.wikidata.query.rdf.tool.wikibase.RecentChangeResponse.RecentChange)6 WikibaseApiError (org.wikidata.query.rdf.tool.wikibase.WikibaseApiError)6 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 Context (com.codahale.metrics.Timer.Context)1 LinkedHashMap (java.util.LinkedHashMap)1