- private static ListeningExecutorService storeExecutor = MoreExecutors.listeningDecorator(MoreExecutors.sameThreadExecutor());
-
- private static final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", storeExecutor);
-
- static {
- store.onGlobalContextUpdated(TestModel.createTestContext());
- }
-
- @Test
- public void testOnReceiveReadData() throws Exception {
- new JavaTestKit(getSystem()) {{
- final Props props = ShardTransaction.props(store.newReadWriteTransaction());
- final ActorRef subject = getSystem().actorOf(props, "testReadData");
-
- new Within(duration("1 seconds")) {
- protected void run() {
-
- subject.tell(new ReadData(InstanceIdentifier.builder().build()), getRef());
-
- final String out = new ExpectMsg<String>("match hint") {
- // do not put code outside this method, will run afterwards
- protected String match(Object in) {
- if (in instanceof ReadDataReply) {
- if (((ReadDataReply) in).getNormalizedNode() != null) {
- return "match";
+ private static ListeningExecutorService storeExecutor =
+ MoreExecutors.listeningDecorator(MoreExecutors.sameThreadExecutor());
+
+ private static final InMemoryDOMDataStore store =
+ new InMemoryDOMDataStore("OPER", storeExecutor, MoreExecutors.sameThreadExecutor());
+
+ private static final SchemaContext testSchemaContext = TestModel.createTestContext();
+
+ private static final ShardIdentifier SHARD_IDENTIFIER =
+ ShardIdentifier.builder().memberName("member-1")
+ .shardName("inventory").type("config").build();
+
+
+ static {
+ store.onGlobalContextUpdated(testSchemaContext);
+ }
+
+ @Test
+ public void testOnReceiveReadData() throws Exception {
+ new JavaTestKit(getSystem()) {{
+ final ActorRef shard = getSystem().actorOf(Shard.props(SHARD_IDENTIFIER, Collections.EMPTY_MAP, null));
+ final Props props =
+ ShardTransaction.props(store.newReadOnlyTransaction(), shard, testSchemaContext);
+ final ActorRef subject = getSystem().actorOf(props, "testReadData");
+
+ new Within(duration("1 seconds")) {
+ @Override
+ protected void run() {
+
+ subject.tell(
+ new ReadData(YangInstanceIdentifier.builder().build()).toSerializable(),
+ getRef());
+
+ final String out = new ExpectMsg<String>(duration("1 seconds"), "match hint") {
+ // do not put code outside this method, will run afterwards
+ @Override
+ protected String match(Object in) {
+ if (in.getClass().equals(ReadDataReply.SERIALIZABLE_CLASS)) {
+ if (ReadDataReply.fromSerializable(testSchemaContext,YangInstanceIdentifier.builder().build(), in)
+ .getNormalizedNode()!= null) {
+ return "match";
+ }
+ return null;
+ } else {
+ throw noMatch();
+ }
+ }
+ }.get(); // this extracts the received message
+
+ assertEquals("match", out);
+
+ expectNoMsg();