Improve segmented journal actor metrics
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / modification / AbstractModificationTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.datastore.modification;
9
10 import com.google.common.util.concurrent.MoreExecutors;
11 import java.util.Optional;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.junit.AfterClass;
14 import org.junit.Before;
15 import org.junit.BeforeClass;
16 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
17 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
18 import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
19 import org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataStore;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
22 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
23 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
24 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
25
26 @Deprecated(since = "9.0.0", forRemoval = true)
27 public abstract class AbstractModificationTest {
28     private static EffectiveModelContext TEST_SCHEMA_CONTEXT;
29
30     static final @NonNull ContainerNode TEST_CONTAINER = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
31
32     protected InMemoryDOMDataStore store;
33
34     @BeforeClass
35     public static void beforeClass() {
36         TEST_SCHEMA_CONTEXT = TestModel.createTestContext();
37     }
38
39     @AfterClass
40     public static void afterClass() {
41         TEST_SCHEMA_CONTEXT = null;
42     }
43
44     @Before
45     public void setUp() {
46         store = new InMemoryDOMDataStore("test", MoreExecutors.newDirectExecutorService());
47         store.onModelContextUpdated(TEST_SCHEMA_CONTEXT);
48     }
49
50     protected void commitTransaction(final DOMStoreWriteTransaction transaction) {
51         DOMStoreThreePhaseCommitCohort cohort = transaction.ready();
52         cohort.preCommit();
53         cohort.commit();
54     }
55
56     protected Optional<NormalizedNode> readData(final YangInstanceIdentifier path) throws Exception {
57         try (var transaction = store.newReadOnlyTransaction()) {
58             return transaction.read(path).get();
59         }
60     }
61 }