added connected flag to imitator to avoid error in the test logs

This commit is contained in:
Volodymyr Babak 2021-05-19 16:45:36 +03:00
parent fb6e152f7e
commit ddfa1c156c

View File

@ -79,6 +79,8 @@ public class EdgeImitator {
@Getter @Getter
private List<AbstractMessage> downlinkMsgs; private List<AbstractMessage> downlinkMsgs;
private boolean connected = false;
public EdgeImitator(String host, int port, String routingKey, String routingSecret) throws NoSuchFieldException, IllegalAccessException { public EdgeImitator(String host, int port, String routingKey, String routingSecret) throws NoSuchFieldException, IllegalAccessException {
edgeRpcClient = new EdgeGrpcClient(); edgeRpcClient = new EdgeGrpcClient();
messagesLatch = new CountDownLatch(0); messagesLatch = new CountDownLatch(0);
@ -100,6 +102,7 @@ public class EdgeImitator {
} }
public void connect() { public void connect() {
connected = true;
edgeRpcClient.connect(routingKey, routingSecret, edgeRpcClient.connect(routingKey, routingSecret,
this::onUplinkResponse, this::onUplinkResponse,
this::onEdgeUpdate, this::onEdgeUpdate,
@ -110,6 +113,7 @@ public class EdgeImitator {
} }
public void disconnect() throws InterruptedException { public void disconnect() throws InterruptedException {
connected = false;
edgeRpcClient.disconnect(false); edgeRpcClient.disconnect(false);
} }
@ -131,15 +135,19 @@ public class EdgeImitator {
Futures.addCallback(future, new FutureCallback<>() { Futures.addCallback(future, new FutureCallback<>() {
@Override @Override
public void onSuccess(@Nullable List<Void> result) { public void onSuccess(@Nullable List<Void> result) {
if (connected) {
DownlinkResponseMsg downlinkResponseMsg = DownlinkResponseMsg.newBuilder().setSuccess(true).build(); DownlinkResponseMsg downlinkResponseMsg = DownlinkResponseMsg.newBuilder().setSuccess(true).build();
edgeRpcClient.sendDownlinkResponseMsg(downlinkResponseMsg); edgeRpcClient.sendDownlinkResponseMsg(downlinkResponseMsg);
} }
}
@Override @Override
public void onFailure(Throwable t) { public void onFailure(Throwable t) {
if (connected) {
DownlinkResponseMsg downlinkResponseMsg = DownlinkResponseMsg.newBuilder().setSuccess(false).setErrorMsg(t.getMessage()).build(); DownlinkResponseMsg downlinkResponseMsg = DownlinkResponseMsg.newBuilder().setSuccess(false).setErrorMsg(t.getMessage()).build();
edgeRpcClient.sendDownlinkResponseMsg(downlinkResponseMsg); edgeRpcClient.sendDownlinkResponseMsg(downlinkResponseMsg);
} }
}
}, MoreExecutors.directExecutor()); }, MoreExecutors.directExecutor());
} }