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);
}
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);
}
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;
}
}
Aggregations