Search in sources :

Example 6 with RecentChange

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

the class WikibaseRepositoryIntegrationTest method recentChangesWithLotsOfChangesHasContinue.

@Test
public void recentChangesWithLotsOfChangesHasContinue() throws RetryableException {
    /*
         * This relies on there being lots of changes in the past 30 days.
         */
    int batchSize = 15;
    RecentChangeResponse changes = repo.get().fetchRecentChanges(START_TIME.minus(30, ChronoUnit.DAYS), null, batchSize);
    assertNotNull(changes.getContinue());
    assertNotNull(changes.getContinue());
    assertNotNull(changes.getQuery());
    RecentChangeResponse.Query query = changes.getQuery();
    assertNotNull(query.getRecentChanges());
    List<RecentChange> recentChanges = changes.getQuery().getRecentChanges();
    assertThat(recentChanges, hasSize(batchSize));
    for (RecentChange rc : recentChanges) {
        assertThat(rc.getNs(), either(equalTo(0L)).or(equalTo(120L)));
        assertNotNull(rc.getTitle());
        assertNotNull(rc.getTimestamp());
        assertNotNull(rc.getRevId());
    }
    final Instant nextDate = repo.get().getChangeFromContinue(changes.getContinue()).timestamp();
    changes = repo.get().fetchRecentChanges(nextDate, null, batchSize);
    assertNotNull(changes.getQuery());
    assertNotNull(changes.getQuery().getRecentChanges());
}
Also used : RecentChange(org.wikidata.query.rdf.tool.wikibase.RecentChangeResponse.RecentChange) Instant(java.time.Instant) Test(org.junit.Test)

Example 7 with RecentChange

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

the class RecentChangesPollerUnitTest method backoffOverflow.

/**
 * Backoff overflow check,
 * Check that if we're backing off but find no new changes then time is advanced.
 * @throws RetryableException
 */
@Test
public void backoffOverflow() throws RetryableException {
    Instant startTime = Instant.now();
    batchSize = 1;
    RecentChangesPoller poller = new RecentChangesPoller(repository, startTime, batchSize, new MetricRegistry());
    WikibaseApiError error = null;
    Continue aContinue = null;
    ArrayList<RecentChange> recentChanges = new ArrayList<>();
    recentChanges.add(new RecentChange(0L, "Q424242", startTime, 42L, 42L, "edit"));
    Query query = new Query(recentChanges);
    RecentChangeResponse result = new RecentChangeResponse(error, aContinue, query);
    firstBatchReturns(startTime, result);
    Batch batch = poller.firstBatch();
    assertThat(batch.changes()).hasSize(1);
    assertThat(batch.leftOffDate()).isEqualTo(startTime);
    batch = poller.nextBatch(batch);
    assertThat(batch.changes()).hasSize(0);
    assertThat(startTime).isBefore(batch.leftOffDate());
    assertThat(startTime.plusSeconds(1)).isEqualTo(batch.leftOffDate());
}
Also used : WikibaseApiError(org.wikidata.query.rdf.tool.wikibase.WikibaseApiError) RecentChange(org.wikidata.query.rdf.tool.wikibase.RecentChangeResponse.RecentChange) 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) ArrayList(java.util.ArrayList) Continue(org.wikidata.query.rdf.tool.wikibase.Continue) RecentChangeResponse(org.wikidata.query.rdf.tool.wikibase.RecentChangeResponse) Test(org.junit.Test)

Example 8 with RecentChange

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

the class RecentChangesPollerUnitTest method backoffTime.

/**
 * Check that recent requests use backoff.
 * @throws RetryableException
 */
@Test
@SuppressWarnings("unchecked")
public void backoffTime() throws RetryableException {
    Instant startTime = Instant.now();
    RecentChangesPoller poller = new RecentChangesPoller(repository, startTime, batchSize, new MetricRegistry());
    Instant nextStartTime = startTime.plusSeconds(20);
    WikibaseApiError error = null;
    Continue aContinue = null;
    List<RecentChange> recentChanges = new ArrayList<>();
    recentChanges.add(new RecentChange(0L, "Q424242", nextStartTime, 42L, 42L, "edit"));
    Query query = new Query(recentChanges);
    RecentChangeResponse result = new RecentChangeResponse(error, aContinue, query);
    ArgumentCaptor<Instant> argument = ArgumentCaptor.forClass(Instant.class);
    when(repository.fetchRecentChangesByTime(argument.capture(), eq(batchSize))).thenReturn(result);
    when(repository.isEntityNamespace(0)).thenReturn(true);
    when(repository.isValidEntity(any(String.class))).thenReturn(true);
    Batch batch = poller.firstBatch();
    // Ensure we backed off at least 7 seconds but no more than 20
    assertThat(argument.getValue()).isBefore(startTime.minusSeconds(7));
    assertThat(argument.getValue()).isAfter(startTime.minusSeconds(20));
    // Verify that backoff still works on the second call
    batch = poller.nextBatch(batch);
    // verify we're still using fetchRecentChangesByTime
    assertThat(batch).isNotNull();
    assertThat(argument.getValue()).isBefore(nextStartTime.minusSeconds(7));
    assertThat(argument.getValue()).isAfter(nextStartTime.minusSeconds(20));
}
Also used : Query(org.wikidata.query.rdf.tool.wikibase.RecentChangeResponse.Query) Instant(java.time.Instant) MetricRegistry(com.codahale.metrics.MetricRegistry) ArrayList(java.util.ArrayList) 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 9 with RecentChange

use of org.wikidata.query.rdf.tool.wikibase.RecentChangeResponse.RecentChange 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)

Aggregations

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