@Test public void testSetRevsLimit() { HttpResponse rsp = mock(HttpResponse.class); when(rsp.isSuccessful()).thenReturn(Boolean.TRUE); when(httpClient.put(anyString(), anyString())).thenReturn(rsp); dbCon.setRevisionLimit(500); verify(httpClient).put("/test_db/_revs_limit", "500"); verify(rsp).releaseConnection(); }
public ContinuousChangesFeed(String dbName, HttpResponse httpResponse) { this.httpResponse = httpResponse; try { reader = new BufferedReader(new InputStreamReader(httpResponse.getContent(), "UTF-8")); thread.setName( String.format( "ektorp-%s-changes-listening-thread-%s", dbName, THREAD_COUNT.getAndIncrement())); thread.start(); } catch (UnsupportedEncodingException e) { throw Exceptions.propagate(e); } }
public void run() { try { String line = reader.readLine(); while (shouldRun && line != null) { if (line.length() > 0) { handleChange(line); } else { handleHeartbeat(); } line = reader.readLine(); } String reason = !shouldRun ? "Cancelled" : "EOF"; LOG.info("Changes feed stopped. Reason: " + reason); } catch (Exception e) { handleException(e); } finally { sendInterruptMarker(); httpResponse.abort(); try { reader.close(); } catch (IOException e) { } } }
@SuppressWarnings("unchecked") @Override public String success(HttpResponse hr) throws Exception { Map<String, ?> rsp = objectMapper.readValue(hr.getContent(), Map.class); return (String) rsp.get(REVISION_FIELD_NAME); }
private HttpResponse setupResponseOnPost() { HttpResponse rsp = mock(HttpResponse.class); when(rsp.isSuccessful()).thenReturn(Boolean.TRUE); when(httpClient.post(anyString(), anyString())).thenReturn(rsp); return rsp; }
@Override public DocumentOperationResult success(HttpResponse hr) throws Exception { return objectMapper.readValue(hr.getContent(), DocumentOperationResult.class); }