Search in sources :

Example 1 with PersisterWithConfiguration

use of org.opendaylight.controller.config.persist.impl.PersisterAggregator.PersisterWithConfiguration in project controller by opendaylight.

the class PersisterAggregatorTest method testLoadFromPropertyFile.

@Test
public void testLoadFromPropertyFile() throws Exception {
    PersisterAggregator persisterAggregator = PersisterAggregator.createFromProperties(TestingPropertiesProvider.loadFile("test2.properties"));
    List<PersisterWithConfiguration> persisters = persisterAggregator.getPersisterWithConfigurations();
    assertEquals(1, persisters.size());
    PersisterWithConfiguration persister = persisters.get(0);
    assertEquals(XmlFileStorageAdapter.class.getName(), persister.getStorage().getClass().getName());
    assertFalse(persister.isReadOnly());
}
Also used : XmlFileStorageAdapter(org.opendaylight.controller.config.persist.storage.file.xml.XmlFileStorageAdapter) PersisterWithConfiguration(org.opendaylight.controller.config.persist.impl.PersisterAggregator.PersisterWithConfiguration) Test(org.junit.Test)

Example 2 with PersisterWithConfiguration

use of org.opendaylight.controller.config.persist.impl.PersisterAggregator.PersisterWithConfiguration in project controller by opendaylight.

the class PersisterAggregatorTest method loadLastConfig.

@Test
public void loadLastConfig() throws Exception {
    List<PersisterWithConfiguration> persisterWithConfigurations = new ArrayList<>();
    PersisterWithConfiguration first = new PersisterWithConfiguration(mockPersister("p0"), false);
    ConfigSnapshotHolder ignored = mockHolder("ignored");
    // should be ignored
    doReturn(Arrays.asList(ignored)).when(first.getStorage()).loadLastConfigs();
    ConfigSnapshotHolder used = mockHolder("used");
    PersisterWithConfiguration second = new PersisterWithConfiguration(mockPersister("p1"), false);
    // should be used
    doReturn(Arrays.asList(used)).when(second.getStorage()).loadLastConfigs();
    PersisterWithConfiguration third = new PersisterWithConfiguration(mockPersister("p2"), false);
    doReturn(Arrays.asList()).when(third.getStorage()).loadLastConfigs();
    persisterWithConfigurations.add(first);
    persisterWithConfigurations.add(second);
    persisterWithConfigurations.add(third);
    try (PersisterAggregator persisterAggregator = new PersisterAggregator(persisterWithConfigurations)) {
        List<ConfigSnapshotHolder> configSnapshotHolderOptional = persisterAggregator.loadLastConfigs();
        assertEquals(1, configSnapshotHolderOptional.size());
        assertEquals(used, configSnapshotHolderOptional.get(0));
    }
}
Also used : ConfigSnapshotHolder(org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder) PersisterWithConfiguration(org.opendaylight.controller.config.persist.impl.PersisterAggregator.PersisterWithConfiguration) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with PersisterWithConfiguration

use of org.opendaylight.controller.config.persist.impl.PersisterAggregator.PersisterWithConfiguration in project controller by opendaylight.

the class PersisterAggregatorTest method testDummyAdapter.

@Test
public void testDummyAdapter() throws Exception {
    PersisterAggregator persisterAggregator = PersisterAggregator.createFromProperties(TestingPropertiesProvider.loadFile("test1.properties"));
    List<PersisterWithConfiguration> persisters = persisterAggregator.getPersisterWithConfigurations();
    assertEquals(1, persisters.size());
    PersisterWithConfiguration persister = persisters.get(0);
    assertEquals(DummyAdapter.class.getName(), persister.getStorage().getClass().getName());
    assertFalse(persister.isReadOnly());
    persisterAggregator.persistConfig(null);
    persisterAggregator.loadLastConfigs();
    persisterAggregator.persistConfig(null);
    persisterAggregator.loadLastConfigs();
    assertEquals(2, DummyAdapter.persist);
    assertEquals(2, DummyAdapter.load);
    assertEquals(1, DummyAdapter.props);
}
Also used : PersisterWithConfiguration(org.opendaylight.controller.config.persist.impl.PersisterAggregator.PersisterWithConfiguration) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 PersisterWithConfiguration (org.opendaylight.controller.config.persist.impl.PersisterAggregator.PersisterWithConfiguration)3 ArrayList (java.util.ArrayList)1 ConfigSnapshotHolder (org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder)1 XmlFileStorageAdapter (org.opendaylight.controller.config.persist.storage.file.xml.XmlFileStorageAdapter)1