use of de.westnordost.osmapi.OsmConnection in project StreetComplete by westnordost.
the class OverpassMapDataDaoTest method testHandleOverpassQuota.
public void testHandleOverpassQuota() throws InterruptedException {
Provider provider = mock(Provider.class);
when(provider.get()).thenReturn(mock(OverpassMapDataParser.class));
OverpassStatus status = new OverpassStatus();
status.availableSlots = 0;
status.nextAvailableSlotIn = 2;
OsmConnection osm = mock(OsmConnection.class);
when(osm.makeRequest(eq("status"), any(OverpassStatusParser.class))).thenReturn(status);
when(osm.makeRequest(eq("interpreter"), eq("POST"), eq(false), any(ApiRequestWriter.class), any(OverpassStatusParser.class))).thenThrow(OsmTooManyRequestsException.class);
final OverpassMapDataDao dao = new OverpassMapDataDao(osm, provider);
// the dao will call get(), get an exception in return, ask its status
// then and at least wait for the specified amount of time before calling again
final boolean[] result = new boolean[1];
Thread dlThread = new Thread() {
@Override
public void run() {
// assert false because we interrupt the thread further down...
result[0] = dao.getAndHandleQuota("", null);
}
};
dlThread.start();
// sleep the wait time: Downloader should not try to call
// overpass again in this time
Thread.sleep(status.nextAvailableSlotIn * 1000);
verify(osm, times(1)).makeRequest(eq("interpreter"), eq("POST"), eq(false), any(ApiRequestWriter.class), any(OverpassStatusParser.class));
verify(osm, times(1)).makeRequest(eq("status"), any(OverpassStatusParser.class));
// now we test if dao will call overpass again after that time. It is not really
// defined when the downloader must call overpass again, lets assume 1.5 secs here and
// change it when it fails
Thread.sleep(1500);
verify(osm, times(2)).makeRequest(eq("interpreter"), eq("POST"), eq(false), any(ApiRequestWriter.class), any(OverpassStatusParser.class));
verify(osm, times(2)).makeRequest(eq("status"), any(OverpassStatusParser.class));
// we are done here, interrupt thread (still part of the test though...)
dlThread.interrupt();
dlThread.join();
assertFalse(result[0]);
}
use of de.westnordost.osmapi.OsmConnection in project StreetComplete by westnordost.
the class UserChangesetsDaoTest method testAmount.
public void testAmount() {
OsmConnection osm = new OsmConnection("https://master.apis.dev.openstreetmap.org/api/0.6/", "StreetComplete test case", null);
long userId = 12;
UserDao userDao = new UserDao(osm);
UserInfo info = userDao.get(userId);
UserChangesetsDao dao = new UserChangesetsDao(new ChangesetsDao(osm));
Counter counter = new Counter();
dao.findAll(counter, userId, new Date(0));
assertEquals(info.changesetsCount, counter.count);
}
Aggregations