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");
}
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
}
}
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());
}
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());
}
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());
}
Aggregations