Search in sources :

Example 6 with ConfigSnapshotHolder

use of org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder in project controller by opendaylight.

the class DirectoryStorageAdapterTest method testTwoFilesAllExtensions.

@Test
public void testTwoFilesAllExtensions() throws Exception {
    File folder = getFolder("twoFiles");
    tested = instantiatePersisterFromAdapter(folder);
    LOG.info("Testing : {}", tested);
    List<ConfigSnapshotHolder> results = tested.loadLastConfigs();
    assertEquals(2, results.size());
    assertResult(results.get(0), "<config>1</config>", "cap1-a", "cap2-a", "capa a-a");
    assertResult(results.get(1), "<config>2</config>", "cap1-b", "cap2-b", "capa a-b");
}
Also used : ConfigSnapshotHolder(org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder) File(java.io.File) Test(org.junit.Test) PropertiesProviderTest(org.opendaylight.controller.config.persist.test.PropertiesProviderTest)

Example 7 with ConfigSnapshotHolder

use of org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder in project controller by opendaylight.

the class DirectoryStorageAdapterTest method testEmptyDirectory.

@Test
public void testEmptyDirectory() throws Exception {
    File folder = new File("target/emptyFolder");
    folder.mkdir();
    tested = instantiatePersisterFromAdapter(folder);
    assertEquals(Collections.<ConfigSnapshotHolder>emptyList(), tested.loadLastConfigs());
    try {
        tested.persistConfig(new ConfigSnapshotHolder() {

            @Override
            public String getConfigSnapshot() {
                throw new RuntimeException();
            }

            @Override
            public SortedSet<String> getCapabilities() {
                throw new RuntimeException();
            }
        });
        fail();
    } catch (final UnsupportedOperationException e) {
    // TODO: empty catch block
    }
}
Also used : ConfigSnapshotHolder(org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder) File(java.io.File) SortedSet(java.util.SortedSet) Test(org.junit.Test) PropertiesProviderTest(org.opendaylight.controller.config.persist.test.PropertiesProviderTest)

Example 8 with ConfigSnapshotHolder

use of org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder in project controller by opendaylight.

the class FileStorageAdapterTest method testFileAdapterOnlyTwoBackups.

@Test
public void testFileAdapterOnlyTwoBackups() throws Exception {
    storage.setFileStorage(file);
    storage.setNumberOfBackups(2);
    final ConfigSnapshotHolder holder = new ConfigSnapshotHolder() {

        @Override
        public String getConfigSnapshot() {
            return createConfig();
        }

        @Override
        public SortedSet<String> getCapabilities() {
            return createCaps();
        }
    };
    storage.persistConfig(holder);
    storage.persistConfig(holder);
    storage.persistConfig(holder);
    List<String> readLines = com.google.common.io.Files.readLines(file, StandardCharsets.UTF_8);
    assertEquals(29, readLines.size());
    List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
    assertEquals(1, lastConf.size());
    ConfigSnapshotHolder configSnapshotHolder = lastConf.get(0);
    assertXMLEqual("<config>3</config>", configSnapshotHolder.getConfigSnapshot());
    assertFalse(readLines.contains(holder.getConfigSnapshot()));
    assertTrue(storage.getPersistedFeatures().isEmpty());
}
Also used : ConfigSnapshotHolder(org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder) Test(org.junit.Test) PropertiesProviderTest(org.opendaylight.controller.config.persist.test.PropertiesProviderTest)

Example 9 with ConfigSnapshotHolder

use of org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder in project controller by opendaylight.

the class FileStorageAdapterTest method testFileAdapter.

@Test
public void testFileAdapter() throws Exception {
    PropertiesProviderTest pp = new PropertiesProviderTest();
    pp.addProperty("fileStorage", file.getPath());
    pp.addProperty("numberOfBackups", Integer.toString(Integer.MAX_VALUE));
    storage.instantiate(pp);
    final ConfigSnapshotHolder holder = new ConfigSnapshotHolder() {

        @Override
        public String getConfigSnapshot() {
            return createConfig();
        }

        @Override
        public SortedSet<String> getCapabilities() {
            return createCaps();
        }
    };
    storage.persistConfig(holder);
    storage.persistConfig(holder);
    assertEquals(29, com.google.common.io.Files.readLines(file, StandardCharsets.UTF_8).size());
    List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
    assertEquals(1, lastConf.size());
    ConfigSnapshotHolder configSnapshotHolder = lastConf.get(0);
    assertXMLEqual("<config>2</config>", configSnapshotHolder.getConfigSnapshot());
    assertEquals(createCaps(), configSnapshotHolder.getCapabilities());
    storage = new XmlFileStorageAdapter();
    storage.setFileStorage(file);
    storage.setNumberOfBackups(Integer.MAX_VALUE);
    List<ConfigSnapshotHolder> last = storage.loadLastConfigs();
    assertEquals(createCaps(), last.get(0).getCapabilities());
}
Also used : ConfigSnapshotHolder(org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder) PropertiesProviderTest(org.opendaylight.controller.config.persist.test.PropertiesProviderTest) Test(org.junit.Test) PropertiesProviderTest(org.opendaylight.controller.config.persist.test.PropertiesProviderTest)

Example 10 with ConfigSnapshotHolder

use of org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder in project controller by opendaylight.

the class FileStorageAdapterTest method testWithFeatures.

@Test
public void testWithFeatures() throws Exception {
    PropertiesProviderTest pp = new PropertiesProviderTest();
    pp.addProperty("fileStorage", file.getPath());
    pp.addProperty("numberOfBackups", Integer.toString(Integer.MAX_VALUE));
    storage.instantiate(pp);
    final ConfigSnapshotHolder holder = new ConfigSnapshotHolder() {

        @Override
        public String getConfigSnapshot() {
            return createConfig();
        }

        @Override
        public SortedSet<String> getCapabilities() {
            return createCaps();
        }
    };
    final FeatureListProvider mock = mock(FeatureListProvider.class);
    doReturn(Sets.newHashSet("f1-11", "f2-22")).when(mock).listFeatures();
    storage.setFeaturesService(mock);
    storage.persistConfig(holder);
    assertEquals(20, com.google.common.io.Files.readLines(file, StandardCharsets.UTF_8).size());
    List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
    assertEquals(1, lastConf.size());
    ConfigSnapshotHolder configSnapshotHolder = lastConf.get(0);
    assertXMLEqual("<config>1</config>", configSnapshotHolder.getConfigSnapshot());
    assertEquals(Sets.newHashSet("f1-11", "f2-22"), storage.getPersistedFeatures());
}
Also used : ConfigSnapshotHolder(org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder) PropertiesProviderTest(org.opendaylight.controller.config.persist.test.PropertiesProviderTest) Test(org.junit.Test) PropertiesProviderTest(org.opendaylight.controller.config.persist.test.PropertiesProviderTest)

Aggregations

ConfigSnapshotHolder (org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder)17 Test (org.junit.Test)13 PropertiesProviderTest (org.opendaylight.controller.config.persist.test.PropertiesProviderTest)12 File (java.io.File)8 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 SortedSet (java.util.SortedSet)1 ConflictingVersionException (org.opendaylight.controller.config.api.ConflictingVersionException)1 ModuleFactoryNotFoundException (org.opendaylight.controller.config.api.ModuleFactoryNotFoundException)1 ValidationException (org.opendaylight.controller.config.api.ValidationException)1 ConfigSubsystemFacadeFactory (org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacadeFactory)1 PersisterAggregator (org.opendaylight.controller.config.persist.impl.PersisterAggregator)1 PersisterWithConfiguration (org.opendaylight.controller.config.persist.impl.PersisterAggregator.PersisterWithConfiguration)1 DocumentedException (org.opendaylight.controller.config.util.xml.DocumentedException)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceTracker (org.osgi.util.tracker.ServiceTracker)1 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)1 SAXException (org.xml.sax.SAXException)1