2 * Copyright (c) 2024 PANTHEON.tech, s.r.o. 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
8 package org.opendaylight.netconf.yanglib.writer;
10 import static org.awaitility.Awaitility.await;
12 import java.time.Duration;
13 import org.junit.Test;
14 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest;
15 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
16 import org.opendaylight.mdsal.dom.spi.FixedDOMSchemaService;
17 import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipService;
18 import org.opendaylight.mdsal.eos.dom.simple.SimpleDOMEntityOwnershipService;
19 import org.opendaylight.mdsal.singleton.impl.EOSClusterSingletonServiceProvider;
20 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.library.rev190104.YangLibrary;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 public class YangLibraryWriterSingletonIntegrationTest extends AbstractConcurrentDataBrokerTest {
24 private final DOMEntityOwnershipService eos = new SimpleDOMEntityOwnershipService();
27 public void testIntegrationNoLegacy() throws Exception {
28 testIntegration(false);
32 public void testIntegrationLegacy() throws Exception {
33 testIntegration(true);
36 private void testIntegration(final boolean writeLegacy) throws Exception {
37 try (var cssProvider = new EOSClusterSingletonServiceProvider(eos)) {
38 try (var singleton = new YangLibraryWriterSingleton(cssProvider, new FixedDOMSchemaService(modelContext()),
39 getDataBroker(), writeLegacy)) {
40 await().atMost(Duration.ofSeconds(5)).until(this::yangLibraryExists);
42 await().atMost(Duration.ofSeconds(5)).until(() -> !yangLibraryExists());
46 private boolean yangLibraryExists() throws Exception {
47 try (var tx = getDataBroker().newReadOnlyTransaction()) {
48 return tx.exists(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(YangLibrary.class)).get();