|
|
@ -21,11 +21,11 @@ import com.google.common.util.concurrent.ListenableFuture; |
|
|
import com.google.common.util.concurrent.MoreExecutors; |
|
|
import com.google.common.util.concurrent.MoreExecutors; |
|
|
import com.google.protobuf.AbstractMessage; |
|
|
import com.google.protobuf.AbstractMessage; |
|
|
import lombok.Getter; |
|
|
import lombok.Getter; |
|
|
|
|
|
import lombok.Setter; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.checkerframework.checker.nullness.qual.Nullable; |
|
|
import org.checkerframework.checker.nullness.qual.Nullable; |
|
|
import org.thingsboard.edge.rpc.EdgeGrpcClient; |
|
|
import org.thingsboard.edge.rpc.EdgeGrpcClient; |
|
|
import org.thingsboard.edge.rpc.EdgeRpcClient; |
|
|
import org.thingsboard.edge.rpc.EdgeRpcClient; |
|
|
import org.thingsboard.server.common.data.id.UserId; |
|
|
|
|
|
import org.thingsboard.server.gen.edge.AlarmUpdateMsg; |
|
|
import org.thingsboard.server.gen.edge.AlarmUpdateMsg; |
|
|
import org.thingsboard.server.gen.edge.AssetUpdateMsg; |
|
|
import org.thingsboard.server.gen.edge.AssetUpdateMsg; |
|
|
import org.thingsboard.server.gen.edge.CustomerUpdateMsg; |
|
|
import org.thingsboard.server.gen.edge.CustomerUpdateMsg; |
|
|
@ -55,6 +55,7 @@ import java.util.ArrayList; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Optional; |
|
|
import java.util.Optional; |
|
|
import java.util.concurrent.CountDownLatch; |
|
|
import java.util.concurrent.CountDownLatch; |
|
|
|
|
|
import java.util.concurrent.ThreadLocalRandom; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
import java.util.concurrent.locks.Lock; |
|
|
import java.util.concurrent.locks.Lock; |
|
|
import java.util.concurrent.locks.ReentrantLock; |
|
|
import java.util.concurrent.locks.ReentrantLock; |
|
|
@ -74,6 +75,11 @@ public class EdgeImitator { |
|
|
private CountDownLatch responsesLatch; |
|
|
private CountDownLatch responsesLatch; |
|
|
private List<Class<? extends AbstractMessage>> ignoredTypes; |
|
|
private List<Class<? extends AbstractMessage>> ignoredTypes; |
|
|
|
|
|
|
|
|
|
|
|
@Setter |
|
|
|
|
|
private boolean randomFailuresOnTimeseriesDownlink = false; |
|
|
|
|
|
@Setter |
|
|
|
|
|
private double failureProbability = 0.0; |
|
|
|
|
|
|
|
|
@Getter |
|
|
@Getter |
|
|
private EdgeConfiguration configuration; |
|
|
private EdgeConfiguration configuration; |
|
|
@Getter |
|
|
@Getter |
|
|
@ -208,7 +214,15 @@ public class EdgeImitator { |
|
|
} |
|
|
} |
|
|
if (downlinkMsg.getEntityDataCount() > 0) { |
|
|
if (downlinkMsg.getEntityDataCount() > 0) { |
|
|
for (EntityDataProto entityData : downlinkMsg.getEntityDataList()) { |
|
|
for (EntityDataProto entityData : downlinkMsg.getEntityDataList()) { |
|
|
result.add(saveDownlinkMsg(entityData)); |
|
|
if (randomFailuresOnTimeseriesDownlink) { |
|
|
|
|
|
if (getRandomBoolean()) { |
|
|
|
|
|
result.add(Futures.immediateFailedFuture(new RuntimeException("Random failure"))); |
|
|
|
|
|
} else { |
|
|
|
|
|
result.add(saveDownlinkMsg(entityData)); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
result.add(saveDownlinkMsg(entityData)); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (downlinkMsg.getEntityViewUpdateMsgCount() > 0) { |
|
|
if (downlinkMsg.getEntityViewUpdateMsgCount() > 0) { |
|
|
@ -254,6 +268,11 @@ public class EdgeImitator { |
|
|
return Futures.allAsList(result); |
|
|
return Futures.allAsList(result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean getRandomBoolean() { |
|
|
|
|
|
double randomValue = ThreadLocalRandom.current().nextDouble() * 100; |
|
|
|
|
|
return randomValue <= this.failureProbability; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private ListenableFuture<Void> saveDownlinkMsg(AbstractMessage message) { |
|
|
private ListenableFuture<Void> saveDownlinkMsg(AbstractMessage message) { |
|
|
if (!ignoredTypes.contains(message.getClass())) { |
|
|
if (!ignoredTypes.contains(message.getClass())) { |
|
|
try { |
|
|
try { |
|
|
@ -271,8 +290,8 @@ public class EdgeImitator { |
|
|
return waitForMessages(5); |
|
|
return waitForMessages(5); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public boolean waitForMessages(int timeout) throws InterruptedException { |
|
|
public boolean waitForMessages(int timeoutInSeconds) throws InterruptedException { |
|
|
return messagesLatch.await(timeout, TimeUnit.SECONDS); |
|
|
return messagesLatch.await(timeoutInSeconds, TimeUnit.SECONDS); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void expectMessageAmount(int messageAmount) { |
|
|
public void expectMessageAmount(int messageAmount) { |
|
|
|