+ };
+ }};
+ }
+
+ @Test
+ public void testApplySnapshot() throws ExecutionException, InterruptedException {
+ Map<ShardIdentifier, String> peerAddresses = new HashMap<>();
+
+ final ShardIdentifier identifier =
+ ShardIdentifier.builder().memberName("member-1")
+ .shardName("inventory").type("config").build();
+
+ peerAddresses.put(identifier, null);
+ final Props props = Shard.props(identifier, peerAddresses, DATA_STORE_CONTEXT, TestModel.createTestContext());
+
+ TestActorRef<Shard> ref = TestActorRef.create(getSystem(), props);
+
+ ref.underlyingActor().updateSchemaContext(TestModel.createTestContext());
+
+ NormalizedNodeToNodeCodec codec =
+ new NormalizedNodeToNodeCodec(TestModel.createTestContext());
+
+ ref.underlyingActor().writeToStore(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
+
+ NormalizedNode expected = ref.underlyingActor().readStore();
+
+ NormalizedNodeMessages.Container encode = codec
+ .encode(YangInstanceIdentifier.builder().build(), expected);
+
+
+ ref.underlyingActor().applySnapshot(encode.getNormalizedNode().toByteString());
+
+ NormalizedNode actual = ref.underlyingActor().readStore();
+
+ assertEquals(expected, actual);
+ }
+
+ private static class ShardTestKit extends JavaTestKit {
+
+ private ShardTestKit(ActorSystem actorSystem) {
+ super(actorSystem);
+ }
+
+ protected void waitForLogMessage(final Class logLevel, ActorRef subject, String logMessage){
+ // Wait for a specific log message to show up
+ final boolean result =
+ new JavaTestKit.EventFilter<Boolean>(logLevel
+ ) {
+ @Override
+ protected Boolean run() {
+ return true;
+ }
+ }.from(subject.path().toString())
+ .message(logMessage)
+ .occurrences(1).exec();
+
+ Assert.assertEquals(true, result);
+
+ }
+
+ }
+
+ @Test
+ public void testCreateSnapshot() throws IOException, InterruptedException {
+ new ShardTestKit(getSystem()) {{
+ final ShardIdentifier identifier =
+ ShardIdentifier.builder().memberName("member-1")
+ .shardName("inventory").type("config").build();
+
+ final Props props = Shard.props(identifier, Collections.EMPTY_MAP, DATA_STORE_CONTEXT, TestModel.createTestContext());
+ final ActorRef subject =
+ getSystem().actorOf(props, "testCreateSnapshot");
+
+ // Wait for a specific log message to show up
+ this.waitForLogMessage(Logging.Info.class, subject, "Switching from state Candidate to Leader");
+
+
+ new Within(duration("3 seconds")) {
+ @Override
+ protected void run() {
+
+ subject.tell(
+ new UpdateSchemaContext(TestModel.createTestContext()),
+ getRef());
+
+ subject.tell(new CaptureSnapshot(-1,-1,-1,-1),
+ getRef());
+
+ waitForLogMessage(Logging.Info.class, subject, "CaptureSnapshotReply received by actor");