Skip to content

Commit

Permalink
FABJ-429 Provide current disconnect handler on peer
Browse files Browse the repository at this point in the history
Change-Id: Iedf594ff0f40f9be87e5ffd088ea75ec705ed7fe
Signed-off-by: rickr <cr22rc@gmail.com>
  • Loading branch information
cr22rc committed Mar 21, 2019
1 parent 3de9ff8 commit d9608f2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/org/hyperledger/fabric/sdk/Peer.java
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,16 @@ public synchronized void disconnected(final PeerEventingServiceDisconnectEvent e
};
}

/**
* Get current disconnect handler service
*
* @return The current disconnect handler service.
*/

public PeerEventingServiceDisconnected getPeerEventingServiceDisconnected() {
return disconnectedHandler;
}

/**
* Set class to handle peer eventing service disconnects
*
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/org/hyperledger/fabric/sdk/PeerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.hyperledger.fabric.protos.peer.FabricProposalResponse;
import org.hyperledger.fabric.sdk.exception.InvalidArgumentException;
import org.hyperledger.fabric.sdk.exception.PeerException;
import org.hyperledger.fabric.sdk.testutils.TestUtils;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Rule;
Expand Down Expand Up @@ -91,4 +92,26 @@ public void testDuplicateChannel() throws InvalidArgumentException {
peer.setChannel(duplicate);
peer.setChannel(duplicate);
}

@Test
public void getPeerEventingServiceDisconnectedTest() throws InvalidArgumentException {
Peer somePeer = hfclient.newPeer("somePeer", "grpc://localhost:4");

final Peer.PeerEventingServiceDisconnected disconnectedHandlerExpect = (Peer.PeerEventingServiceDisconnected) TestUtils.getField(somePeer, "disconnectedHandler");

Peer.PeerEventingServiceDisconnected disconnectedHandler = somePeer.getPeerEventingServiceDisconnected();

Assert.assertSame(disconnectedHandlerExpect, disconnectedHandler);

Peer.PeerEventingServiceDisconnected peerEventingServiceDisconnectedCurrent = somePeer.setPeerEventingServiceDisconnected(null);

Assert.assertSame(disconnectedHandlerExpect, peerEventingServiceDisconnectedCurrent);

Assert.assertNull(somePeer.getPeerEventingServiceDisconnected());

Assert.assertNull(somePeer.setPeerEventingServiceDisconnected(disconnectedHandlerExpect));

Assert.assertSame(disconnectedHandlerExpect, somePeer.getPeerEventingServiceDisconnected());

}
}

0 comments on commit d9608f2

Please sign in to comment.