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