use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.
the class AbstractReplicatedLogImplTest method testGetFromWithMax.
@Test
public void testGetFromWithMax() {
List<ReplicatedLogEntry> from = replicatedLogImpl.getFrom(0, 1, ReplicatedLog.NO_MAX_SIZE);
Assert.assertEquals(1, from.size());
Assert.assertEquals("A", from.get(0).getData().toString());
from = replicatedLogImpl.getFrom(0, 20, ReplicatedLog.NO_MAX_SIZE);
Assert.assertEquals(4, from.size());
Assert.assertEquals("A", from.get(0).getData().toString());
Assert.assertEquals("D", from.get(3).getData().toString());
from = replicatedLogImpl.getFrom(1, 2, ReplicatedLog.NO_MAX_SIZE);
Assert.assertEquals(2, from.size());
Assert.assertEquals("B", from.get(0).getData().toString());
Assert.assertEquals("C", from.get(1).getData().toString());
from = replicatedLogImpl.getFrom(1, 3, 2);
Assert.assertEquals(2, from.size());
Assert.assertEquals("B", from.get(0).getData().toString());
Assert.assertEquals("C", from.get(1).getData().toString());
from = replicatedLogImpl.getFrom(1, 3, 3);
Assert.assertEquals(3, from.size());
Assert.assertEquals("B", from.get(0).getData().toString());
Assert.assertEquals("C", from.get(1).getData().toString());
Assert.assertEquals("D", from.get(2).getData().toString());
from = replicatedLogImpl.getFrom(1, 2, 3);
Assert.assertEquals(2, from.size());
Assert.assertEquals("B", from.get(0).getData().toString());
Assert.assertEquals("C", from.get(1).getData().toString());
replicatedLogImpl.append(new SimpleReplicatedLogEntry(4, 2, new MockPayload("12345")));
from = replicatedLogImpl.getFrom(4, 2, 2);
Assert.assertEquals(1, from.size());
Assert.assertEquals("12345", from.get(0).getData().toString());
}
use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.
the class AbstractReplicatedLogImplTest method testIsPresent.
@Test
public void testIsPresent() {
assertTrue(replicatedLogImpl.isPresent(0));
assertTrue(replicatedLogImpl.isPresent(1));
assertTrue(replicatedLogImpl.isPresent(2));
assertTrue(replicatedLogImpl.isPresent(3));
replicatedLogImpl.append(new SimpleReplicatedLogEntry(4, 2, new MockPayload("D")));
// snapshot on 3
replicatedLogImpl.snapshotPreCommit(3, 2);
replicatedLogImpl.snapshotCommit();
assertFalse(replicatedLogImpl.isPresent(0));
assertFalse(replicatedLogImpl.isPresent(1));
assertFalse(replicatedLogImpl.isPresent(2));
assertFalse(replicatedLogImpl.isPresent(3));
assertTrue(replicatedLogImpl.isPresent(4));
// snapshot on 4
replicatedLogImpl.snapshotPreCommit(4, 2);
replicatedLogImpl.snapshotCommit();
assertFalse(replicatedLogImpl.isPresent(4));
replicatedLogImpl.append(new SimpleReplicatedLogEntry(5, 2, new MockPayload("D")));
assertTrue(replicatedLogImpl.isPresent(5));
}
use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.
the class AbstractReplicatedLogImplTest method testIndexOperations.
@Test
public void testIndexOperations() {
// check if the values returned are correct, with snapshotIndex = -1
assertEquals("B", replicatedLogImpl.get(1).getData().toString());
assertEquals("D", replicatedLogImpl.last().getData().toString());
assertEquals(3, replicatedLogImpl.lastIndex());
assertEquals(2, replicatedLogImpl.lastTerm());
assertEquals(2, replicatedLogImpl.getFrom(2).size());
assertEquals(4, replicatedLogImpl.size());
assertTrue(replicatedLogImpl.isPresent(2));
assertFalse(replicatedLogImpl.isPresent(4));
assertFalse(replicatedLogImpl.isInSnapshot(2));
// now create a snapshot of 3 entries, with 1 unapplied entry left in the log
// It removes the entries which have made it to snapshot
// and updates the snapshot index and term
takeSnapshot(3);
// check the values after the snapshot.
// each index value passed in the test is the logical index (log entry index)
// which gets mapped to the list's physical index
assertEquals("D", replicatedLogImpl.get(3).getData().toString());
assertEquals("D", replicatedLogImpl.last().getData().toString());
assertNull(replicatedLogImpl.get(1));
assertEquals(3, replicatedLogImpl.lastIndex());
assertEquals(2, replicatedLogImpl.lastTerm());
assertEquals(0, replicatedLogImpl.getFrom(2).size());
assertEquals(1, replicatedLogImpl.size());
assertFalse(replicatedLogImpl.isPresent(2));
assertTrue(replicatedLogImpl.isPresent(3));
assertFalse(replicatedLogImpl.isPresent(4));
assertTrue(replicatedLogImpl.isInSnapshot(2));
// append few more entries
replicatedLogImpl.append(new SimpleReplicatedLogEntry(4, 2, new MockPayload("E")));
replicatedLogImpl.append(new SimpleReplicatedLogEntry(5, 2, new MockPayload("F")));
replicatedLogImpl.append(new SimpleReplicatedLogEntry(6, 3, new MockPayload("G")));
replicatedLogImpl.append(new SimpleReplicatedLogEntry(7, 3, new MockPayload("H")));
// check their values as well
assertEquals(5, replicatedLogImpl.size());
assertEquals("D", replicatedLogImpl.get(3).getData().toString());
assertEquals("E", replicatedLogImpl.get(4).getData().toString());
assertEquals("H", replicatedLogImpl.last().getData().toString());
assertEquals(3, replicatedLogImpl.lastTerm());
assertEquals(7, replicatedLogImpl.lastIndex());
assertTrue(replicatedLogImpl.isPresent(7));
assertFalse(replicatedLogImpl.isInSnapshot(7));
assertEquals(1, replicatedLogImpl.getFrom(7).size());
assertEquals(2, replicatedLogImpl.getFrom(6).size());
// take a second snapshot with 5 entries with 0 unapplied entries left in the log
takeSnapshot(5);
assertEquals(0, replicatedLogImpl.size());
assertNull(replicatedLogImpl.last());
assertNull(replicatedLogImpl.get(7));
assertNull(replicatedLogImpl.get(1));
assertFalse(replicatedLogImpl.isPresent(7));
assertTrue(replicatedLogImpl.isInSnapshot(7));
assertEquals(0, replicatedLogImpl.getFrom(7).size());
assertEquals(0, replicatedLogImpl.getFrom(6).size());
}
use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.
the class AppendEntriesTest method testSerialization.
@Test
public void testSerialization() {
ReplicatedLogEntry entry1 = new SimpleReplicatedLogEntry(1, 2, new MockPayload("payload1"));
ReplicatedLogEntry entry2 = new SimpleReplicatedLogEntry(3, 4, new MockPayload("payload2"));
short payloadVersion = 5;
AppendEntries expected = new AppendEntries(5L, "node1", 7L, 8L, Arrays.asList(entry1, entry2), 10L, -1, payloadVersion);
AppendEntries cloned = (AppendEntries) SerializationUtils.clone(expected);
verifyAppendEntries(expected, cloned);
}
use of org.opendaylight.controller.cluster.raft.persisted.SimpleReplicatedLogEntry in project controller by opendaylight.
the class ClusterAdminRpcServiceTest method setupPersistedServerConfigPayload.
private static void setupPersistedServerConfigPayload(ServerConfigurationPayload serverConfig, String member, String datastoreTypeSuffix, String... shards) {
String[] datastoreTypes = { "config_", "oper_" };
for (String type : datastoreTypes) {
for (String shard : shards) {
List<ServerInfo> newServerInfo = new ArrayList<>(serverConfig.getServerConfig().size());
for (ServerInfo info : serverConfig.getServerConfig()) {
newServerInfo.add(new ServerInfo(ShardIdentifier.create(shard, MemberName.forName(info.getId()), type + datastoreTypeSuffix).toString(), info.isVoting()));
}
String shardID = ShardIdentifier.create(shard, MemberName.forName(member), type + datastoreTypeSuffix).toString();
InMemoryJournal.addEntry(shardID, 1, new UpdateElectionTerm(1, null));
InMemoryJournal.addEntry(shardID, 2, new SimpleReplicatedLogEntry(0, 1, new ServerConfigurationPayload(newServerInfo)));
}
}
}
Aggregations