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;
12 import static org.junit.Assert.assertTrue;
14 import com.google.common.base.Optional;
15 import com.google.common.collect.ClassToInstanceMap;
16 import com.google.common.collect.ImmutableClassToInstanceMap;
17 import com.google.common.collect.Maps;
18 import com.google.common.util.concurrent.ListenableFuture;
19 import java.util.Collection;
20 import java.util.Collections;
22 import javax.annotation.Nonnull;
23 import org.junit.After;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
27 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
28 import org.opendaylight.mdsal.dom.api.DOMDataTreeListener;
29 import org.opendaylight.mdsal.dom.api.DOMDataTreeLoopException;
30 import org.opendaylight.mdsal.dom.api.DOMDataTreeProducer;
31 import org.opendaylight.mdsal.dom.api.DOMDataTreeService;
32 import org.opendaylight.mdsal.dom.api.DOMDataTreeServiceExtension;
33 import org.opendaylight.mdsal.dom.broker.util.TestModel;
34 import org.opendaylight.yangtools.concepts.ListenerRegistration;
35 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
36 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidates;
38 public class ShardedDOMReadTransactionAdapterTest {
40 private ShardedDOMReadTransactionAdapter readTx;
44 readTx = new ShardedDOMReadTransactionAdapter("TEST-TX", new TestTreeService());
48 public void testGetIdentifier() {
49 assertEquals("TEST-TX", readTx.getIdentifier());
53 public void testRead() throws Exception {
54 final ListenableFuture<Optional<NormalizedNode<?, ?>>> readResult =
55 readTx.read(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH);
56 assertTrue(readTx.exists(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH).get());
57 assertEquals(readResult.get().get(), TestUtils.TEST_CONTAINER);
61 public void close() throws Exception {
65 private static class TestTreeService implements DOMDataTreeService {
69 public Map<Class<? extends DOMDataTreeServiceExtension>, DOMDataTreeServiceExtension> getSupportedExtensions() {
70 return ImmutableClassToInstanceMap.of();
74 public ClassToInstanceMap<DOMDataTreeServiceExtension> getExtensions() {
75 return ImmutableClassToInstanceMap.of();
80 public <T extends DOMDataTreeListener> ListenerRegistration<T>
81 registerListener(@Nonnull final T listener, @Nonnull final Collection<DOMDataTreeIdentifier> subtrees,
82 final boolean allowRxMerges,
83 @Nonnull final Collection<DOMDataTreeProducer> producers) throws DOMDataTreeLoopException {
84 final Map<DOMDataTreeIdentifier, NormalizedNode<?, ?>> subtree = Maps.newHashMap();
85 subtree.put(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, TestModel.TEST_PATH),
86 TestUtils.TEST_CONTAINER);
88 listener.onDataTreeChanged(Collections.singleton(
89 DataTreeCandidates.fromNormalizedNode(TestModel.TEST_PATH, TestUtils.TEST_CONTAINER)), subtree);
91 return new ListenerRegistration<T>() {
98 public T getInstance() {
106 public DOMDataTreeProducer createProducer(@Nonnull final Collection<DOMDataTreeIdentifier> subtrees) {