+
+ @SuppressFBWarnings("BC_UNCONFIRMED_CAST")
+ public String diffWithLocalCopy(final NormalizedNode<?, ?> expected) {
+ return diffNodes((MapNode)expected, (MapNode)localCopy);
+ }
+
+ public Future<Void> tryFinishProcessing() {
+ executorService = Executors.newSingleThreadScheduledExecutor();
+ final SettableFuture<Void> settableFuture = SettableFuture.create();
+
+ scheduledFuture = executorService.scheduleAtFixedRate(new CheckFinishedTask(settableFuture),
+ 0, 1, TimeUnit.SECONDS);
+ return settableFuture;
+ }
+
+ public static String diffNodes(final MapNode expected, final MapNode actual) {
+ StringBuilder builder = new StringBuilder("MapNodes diff:");
+
+ final YangInstanceIdentifier.NodeIdentifier itemNodeId = new YangInstanceIdentifier.NodeIdentifier(ITEM);
+
+ Map<NodeIdentifierWithPredicates, MapEntryNode> expIdIntMap = new HashMap<>();
+ expected.getValue().forEach(node -> expIdIntMap.put(node.getIdentifier(), node));
+
+ actual.getValue().forEach(actIdInt -> {
+ final MapEntryNode expIdInt = expIdIntMap.remove(actIdInt.getIdentifier());
+ if (expIdInt == null) {
+ builder.append('\n').append(" Unexpected id-int entry for ").append(actIdInt.getIdentifier());
+ return;
+ }
+
+ Map<NodeIdentifierWithPredicates, MapEntryNode> expItemMap = new HashMap<>();
+ ((MapNode)expIdInt.getChild(itemNodeId).get()).getValue()
+ .forEach(node -> expItemMap.put(node.getIdentifier(), node));
+
+ ((MapNode)actIdInt.getChild(itemNodeId).get()).getValue().forEach(actItem -> {
+ final MapEntryNode expItem = expItemMap.remove(actItem.getIdentifier());
+ if (expItem == null) {
+ builder.append('\n').append(" Unexpected item entry ").append(actItem.getIdentifier())
+ .append(" for id-int entry ").append(actIdInt.getIdentifier());
+ }
+ });
+
+ expItemMap.values().forEach(node -> builder.append('\n')
+ .append(" Actual is missing item entry ").append(node.getIdentifier())
+ .append(" for id-int entry ").append(actIdInt.getIdentifier()));
+ });
+
+ expIdIntMap.values().forEach(node -> builder.append('\n')
+ .append(" Actual is missing id-int entry for ").append(node.getIdentifier()));
+
+ return builder.toString();
+ }
+
+ private class CheckFinishedTask implements Runnable {
+
+ private final SettableFuture<Void> future;
+
+ CheckFinishedTask(final SettableFuture<Void> future) {
+ this.future = future;
+ }
+
+ @Override
+ public void run() {
+ if (System.nanoTime() - lastNotifTimestamp.get() > SECOND_AS_NANO * 4) {
+ scheduledFuture.cancel(false);
+ future.set(null);
+
+ executorService.shutdown();
+ }
+ }
+ }