summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
09d76ff)
Make sure we close the read transaction and improve assertions with
Optional.
Change-Id: Ia465f64c5845e3d5e215759cc32048e06478104b
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
*/
package org.opendaylight.controller.cluster.datastore.modification;
*/
package org.opendaylight.controller.cluster.datastore.modification;
-import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.Optional;
import com.google.common.util.concurrent.MoreExecutors;
import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
-import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction;
import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
import org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataStore;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
import org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataStore;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
public abstract class AbstractModificationTest {
private static EffectiveModelContext TEST_SCHEMA_CONTEXT;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
public abstract class AbstractModificationTest {
private static EffectiveModelContext TEST_SCHEMA_CONTEXT;
+ static final @NonNull ContainerNode TEST_CONTAINER = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
+
protected InMemoryDOMDataStore store;
@BeforeClass
protected InMemoryDOMDataStore store;
@BeforeClass
}
protected Optional<NormalizedNode> readData(final YangInstanceIdentifier path) throws Exception {
}
protected Optional<NormalizedNode> readData(final YangInstanceIdentifier path) throws Exception {
- // FIXME: close the transaction
- DOMStoreReadTransaction transaction = store.newReadOnlyTransaction();
- ListenableFuture<Optional<NormalizedNode>> future = transaction.read(path);
- return future.get();
+ try (var transaction = store.newReadOnlyTransaction()) {
+ return transaction.read(path).get();
+ }
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.controller.cluster.datastore.modification;
import static org.junit.Assert.assertEquals;
import java.util.Optional;
import org.apache.commons.lang.SerializationUtils;
package org.opendaylight.controller.cluster.datastore.modification;
import static org.junit.Assert.assertEquals;
import java.util.Optional;
import org.apache.commons.lang.SerializationUtils;
-import org.junit.Assert;
import org.junit.Test;
import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.junit.Test;
import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
public class DeleteModificationTest extends AbstractModificationTest {
public class DeleteModificationTest extends AbstractModificationTest {
@Test
public void testApply() throws Exception {
// Write something into the datastore
DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
@Test
public void testApply() throws Exception {
// Write something into the datastore
DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
- WriteModification writeModification = new WriteModification(TestModel.TEST_PATH,
- ImmutableNodes.containerNode(TestModel.TEST_QNAME));
+ WriteModification writeModification = new WriteModification(TestModel.TEST_PATH, TEST_CONTAINER);
writeModification.apply(writeTransaction);
commitTransaction(writeTransaction);
// Check if it's in the datastore
writeModification.apply(writeTransaction);
commitTransaction(writeTransaction);
// Check if it's in the datastore
- Optional<NormalizedNode> data = readData(TestModel.TEST_PATH);
- Assert.assertTrue(data.isPresent());
+ assertEquals(Optional.of(TEST_CONTAINER), readData(TestModel.TEST_PATH));
// Delete stuff from the datastore
DOMStoreWriteTransaction deleteTransaction = store.newWriteOnlyTransaction();
// Delete stuff from the datastore
DOMStoreWriteTransaction deleteTransaction = store.newWriteOnlyTransaction();
deleteModification.apply(deleteTransaction);
commitTransaction(deleteTransaction);
deleteModification.apply(deleteTransaction);
commitTransaction(deleteTransaction);
- data = readData(TestModel.TEST_PATH);
- Assert.assertFalse(data.isPresent());
+ assertEquals(Optional.empty(), readData(TestModel.TEST_PATH));
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.controller.cluster.datastore.modification;
import static org.junit.Assert.assertEquals;
import java.util.Optional;
import org.apache.commons.lang.SerializationUtils;
package org.opendaylight.controller.cluster.datastore.modification;
import static org.junit.Assert.assertEquals;
import java.util.Optional;
import org.apache.commons.lang.SerializationUtils;
-import org.junit.Assert;
import org.junit.Test;
import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
import org.junit.Test;
import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
public class MergeModificationTest extends AbstractModificationTest {
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
public class MergeModificationTest extends AbstractModificationTest {
@Test
public void testApply() throws Exception {
//TODO : Need to write a better test for this
@Test
public void testApply() throws Exception {
//TODO : Need to write a better test for this
commitTransaction(writeTransaction);
//Check if it's in the datastore
commitTransaction(writeTransaction);
//Check if it's in the datastore
- Optional<NormalizedNode> data = readData(TestModel.TEST_PATH);
- Assert.assertTrue(data.isPresent());
-
+ assertEquals(Optional.of(TEST_CONTAINER), readData(TestModel.TEST_PATH));
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
package org.opendaylight.controller.cluster.datastore.modification;
import static org.junit.Assert.assertEquals;
import java.util.Optional;
import org.apache.commons.lang.SerializationUtils;
package org.opendaylight.controller.cluster.datastore.modification;
import static org.junit.Assert.assertEquals;
import java.util.Optional;
import org.apache.commons.lang.SerializationUtils;
-import org.junit.Assert;
import org.junit.Test;
import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
import org.junit.Test;
import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadWriteTransaction;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
public class WriteModificationTest extends AbstractModificationTest {
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
public class WriteModificationTest extends AbstractModificationTest {
@Test
public void testApply() throws Exception {
//Write something into the datastore
DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
@Test
public void testApply() throws Exception {
//Write something into the datastore
DOMStoreReadWriteTransaction writeTransaction = store.newReadWriteTransaction();
- WriteModification writeModification = new WriteModification(TestModel.TEST_PATH,
- ImmutableNodes.containerNode(TestModel.TEST_QNAME));
+ WriteModification writeModification = new WriteModification(TestModel.TEST_PATH, TEST_CONTAINER);
writeModification.apply(writeTransaction);
commitTransaction(writeTransaction);
//Check if it's in the datastore
writeModification.apply(writeTransaction);
commitTransaction(writeTransaction);
//Check if it's in the datastore
- Optional<NormalizedNode> data = readData(TestModel.TEST_PATH);
- Assert.assertTrue(data.isPresent());
+ assertEquals(Optional.of(TEST_CONTAINER), readData(TestModel.TEST_PATH));