/** * Makes a call to ShapeShift about the time left for the trade * * Note: do not call this from the main thread! */ @Nullable private static ShapeShiftTime getTimeLeftSync(ShapeShift shapeShift, AbstractAddress address) { // Try 3 times for (int tries = 1; tries <= 3; tries++) { try { log.info("Getting time left for: {}", address); return shapeShift.getTime(address); } catch (Exception e) { log.info("Will retry: {}", e.getMessage()); /* ignore and retry, with linear backoff */ try { Thread.sleep(1000 * tries); } catch (InterruptedException ie) { /*ignored*/ } } } return null; }
@Test public void testGetTime() throws ShapeShiftException, IOException, InterruptedException, JSONException, AddressMalformedException { // Schedule some responses. server.enqueue(new MockResponse().setBody(GET_TIME_PENDING_JSON)); server.enqueue(new MockResponse().setBody(GET_TIME_EXPIRED_JSON)); AbstractAddress address = NuBitsMain.get().newAddress("BPjxHqswNZB5vznbrAAxi5zGVq3ruhtBU8"); ShapeShiftTime timeReply = shapeShift.getTime(address); assertFalse(timeReply.isError); assertEquals(ShapeShiftTime.Status.PENDING, timeReply.status); assertEquals(100, timeReply.secondsRemaining); timeReply = shapeShift.getTime(address); assertFalse(timeReply.isError); assertEquals(ShapeShiftTime.Status.EXPIRED, timeReply.status); assertEquals(0, timeReply.secondsRemaining); // Optional: confirm that your app made the HTTP requests you were expecting. RecordedRequest request = server.takeRequest(); assertEquals("/timeremaining/BPjxHqswNZB5vznbrAAxi5zGVq3ruhtBU8", request.getPath()); request = server.takeRequest(); assertEquals("/timeremaining/BPjxHqswNZB5vznbrAAxi5zGVq3ruhtBU8", request.getPath()); }