2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.mdsal.dom.broker;
11 import static org.junit.Assert.assertEquals;
13 import com.google.common.base.Optional;
14 import com.google.common.collect.Maps;
15 import com.google.common.util.concurrent.CheckedFuture;
16 import java.util.Collection;
17 import java.util.Collections;
19 import javax.annotation.Nonnull;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
23 import org.opendaylight.mdsal.common.api.ReadFailedException;
24 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
25 import org.opendaylight.mdsal.dom.api.DOMDataTreeListener;
26 import org.opendaylight.mdsal.dom.api.DOMDataTreeLoopException;
27 import org.opendaylight.mdsal.dom.api.DOMDataTreeProducer;
28 import org.opendaylight.mdsal.dom.api.DOMDataTreeService;
29 import org.opendaylight.mdsal.dom.broker.util.TestModel;
30 import org.opendaylight.yangtools.concepts.ListenerRegistration;
31 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
32 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
34 public class ShardedDOMReadTransactionAdapterTest {
36 private ShardedDOMReadTransactionAdapter readTx;
40 readTx = new ShardedDOMReadTransactionAdapter("TEST-TX", new TestTreeService());
44 public void testGetIdentifier() {
45 assertEquals("TEST-TX", readTx.getIdentifier());
49 public void testRead() throws Exception {
50 final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readResult =
51 readTx.read(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
52 assertEquals(readResult.checkedGet().get(), TestUtils.TEST_CONTAINER);
56 private static class TestTreeService implements DOMDataTreeService {
60 public <T extends DOMDataTreeListener> ListenerRegistration<T>
61 registerListener(@Nonnull final T listener, @Nonnull final Collection<DOMDataTreeIdentifier> subtrees,
62 final boolean allowRxMerges,
63 @Nonnull final Collection<DOMDataTreeProducer> producers) throws DOMDataTreeLoopException {
64 final Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>> subtree = Maps.newHashMap();
65 subtree.put(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH),
66 TestUtils.TEST_CONTAINER);
68 listener.onDataTreeChanged(Collections.singleton(
69 DataTreeCandidates.fromNormalizedNode(TestModel.TEST_PATH, TestUtils.TEST_CONTAINER)), subtree);
71 return new ListenerRegistration<T>() {
78 public T getInstance() {
86 public DOMDataTreeProducer createProducer(@Nonnull final Collection<DOMDataTreeIdentifier> subtrees) {