@Test
public void getGetRequestsReturnsGetRequests() throws IOException, FcpException {
- FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), this::sendRequests);
+ FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), sendRequests(this::sendRequests, this::endListPersistentRequests));
try (FcpClient fcpClient = new FcpClient(fcpConnection)) {
Collection<Request> requests = fcpClient.getGetRequests(false);
assertThat(requests, contains(isGetRequest(equalTo("get1"))));
@Test
public void getPutRequestsReturnsPutRequests() throws IOException, FcpException {
- FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), this::sendRequests);
+ FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), sendRequests(this::sendRequests, this::endListPersistentRequests));
try (FcpClient fcpClient = new FcpClient(fcpConnection)) {
Collection<Request> requests = fcpClient.getPutRequests(false);
assertThat(requests, contains(isPutRequest(equalTo("put1")), isPutRequest(equalTo("put2"))));
@Test
public void getGetRequestsWithGlobalReturnsGlobalGetRequests() throws IOException, FcpException {
- FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), this::sendRequests);
+ FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), sendRequests(this::sendRequests, this::endListPersistentRequests));
try (FcpClient fcpClient = new FcpClient(fcpConnection)) {
Collection<Request> requests = fcpClient.getGetRequests(true);
assertThat(requests, containsInAnyOrder(isGetRequest(equalTo("get1")), isGetRequest(equalTo("get1-global"))));
@Test
public void getPutRequestsWithGlobalReturnsGlobalPutRequests() throws IOException, FcpException {
- FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), this::sendRequests);
+ FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), sendRequests(this::sendRequests, this::endListPersistentRequests));
try (FcpClient fcpClient = new FcpClient(fcpConnection)) {
Collection<Request> requests = fcpClient.getPutRequests(true);
assertThat(requests, containsInAnyOrder(
@Test
public void getGetRequestsIsCompleteWhenDataFoundMessageIsReceived() throws IOException, FcpException {
- FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), sendRequests(this::sendRequests, this::sendDataFound));
+ FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), sendRequests(this::sendRequests, this::sendDataFound, this::endListPersistentRequests));
try (FcpClient fcpClient = new FcpClient(fcpConnection)) {
Collection<Request> requests = fcpClient.getGetRequests(false);
assertThat(requests, contains(isGetRequest(
@Test
public void getRequestsIgnoresDataFoundForUnknownIdentifier() throws IOException, FcpException {
- FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), sendRequests(this::sendRequests, this::sendDataFoundForUnknownIdentifier));
+ FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), sendRequests(this::sendRequests, this::sendDataFoundForUnknownIdentifier, this::endListPersistentRequests));
try (FcpClient fcpClient = new FcpClient(fcpConnection)) {
Collection<Request> requests = fcpClient.getRequests(true);
assertThat(requests, containsInAnyOrder(
@Test
public void getGetRequestIsCompleteAndFailedWhenGetFailedMessageIsReceived() throws Exception {
- FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), sendRequests(this::sendRequests, this::sendGetFailed));
+ FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), sendRequests(this::sendRequests, this::sendGetFailed, this::endListPersistentRequests));
try (FcpClient fcpClient = new FcpClient(fcpConnection)) {
Collection<Request> requests = fcpClient.getGetRequests(false);
assertThat(requests, contains(isGetRequest(
@Test
public void getRequestIgnoresGetFailedForUnknownIdentifier() throws Exception {
- FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), sendRequests(this::sendRequests, this::sendGetFailedForUnknownIdentifier));
+ FcpConnection fcpConnection = createFcpConnectionReactingToSingleMessage(named("ListPersistentRequests"), sendRequests(this::sendRequests, this::sendGetFailedForUnknownIdentifier, this::endListPersistentRequests));
try (FcpClient fcpClient = new FcpClient(fcpConnection)) {
Collection<Request> requests = fcpClient.getRequests(true);
assertThat(requests, containsInAnyOrder(
listener.receivedPersistentPutDir(connection, new PersistentPutDir(new FcpMessage("PersistentPutDir").put("Identifier", "putdir1-global").put("Global", "true")));
listener.receivedPersistentPutDir(connection, new PersistentPutDir(new FcpMessage("PersistentPutDir").put("Identifier", "putdir2-global").put("Global", "true")));
listener.receivedPersistentPutDir(connection, new PersistentPutDir(new FcpMessage("PersistentPutDir").put("Identifier", "putdir3-global").put("Global", "true")));
+ }
+
+ private void endListPersistentRequests(FcpListener listener, FcpConnection connection) {
listener.receivedEndListPersistentRequests(connection, new EndListPersistentRequests(new FcpMessage("EndListPersistentRequests")));
}