use of org.corfudb.runtime.view.Layout in project CorfuDB by CorfuDB.
the class AbstractReplicationProtocolTest method overwriteThrowsException.
/** Check to make sure that overwriting a previously
* written entry results in an OverwriteException.
*/
@Test
@SuppressWarnings("unchecked")
public void overwriteThrowsException() throws Exception {
setupNodes();
//begin tests
final CorfuRuntime r = getDefaultRuntime();
final IReplicationProtocol rp = getProtocol();
final Layout layout = r.getLayoutView().getLayout();
LogData d1 = getLogData(0, "1".getBytes());
LogData d2 = getLogData(0, "2".getBytes());
rp.write(layout, d1);
assertThatThrownBy(() -> rp.write(layout, d2)).isInstanceOf(OverwriteException.class);
}
use of org.corfudb.runtime.view.Layout in project CorfuDB by CorfuDB.
the class ChainReplicationProtocolTest method failedWriteIsPropagated.
/** Check to see that a writer correctly
* completes a failed write from another client.
*/
@Test
public void failedWriteIsPropagated() throws Exception {
setupNodes();
//begin tests
final CorfuRuntime r = getDefaultRuntime();
final IReplicationProtocol rp = getProtocol();
final Layout layout = r.getLayoutView().getLayout();
LogData failedWrite = getLogData(0, "failed".getBytes());
LogData incompleteWrite = getLogData(0, "incomplete".getBytes());
// Write the incomplete write to the head of the chain
r.getRouter(SERVERS.ENDPOINT_0).getClient(LogUnitClient.class).write(incompleteWrite);
// Attempt to write using the replication protocol.
// Should result in an overwrite exception
assertThatThrownBy(() -> rp.write(layout, failedWrite)).isInstanceOf(OverwriteException.class);
// At this point, a direct read of the tail should
// reflect the -other- clients value
ILogData readResult = r.getRouter(SERVERS.ENDPOINT_0).getClient(LogUnitClient.class).read(0).get().getReadSet().get(0L);
assertThat(readResult.getPayload(r)).isEqualTo("incomplete".getBytes());
}
use of org.corfudb.runtime.view.Layout in project CorfuDB by CorfuDB.
the class SMRMultiLogunitTest method setRuntime.
@Before
public void setRuntime() {
addServer(SERVERS.PORT_0);
addServer(SERVERS.PORT_1);
addServer(SERVERS.PORT_2);
Layout layout = new TestLayoutBuilder().setEpoch(1L).addLayoutServer(SERVERS.PORT_0).addLayoutServer(SERVERS.PORT_1).addLayoutServer(SERVERS.PORT_2).addSequencer(SERVERS.PORT_0).buildSegment().buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_1).addLogUnit(SERVERS.PORT_2).addToSegment().addToLayout().build();
bootstrapAllServers(layout);
runtime = getRuntime().connect();
}
use of org.corfudb.runtime.view.Layout in project CorfuDB by CorfuDB.
the class LayoutClientTest method prepareRejectsLowerRanks.
@Test
public void prepareRejectsLowerRanks() throws Exception {
Layout layout = TestLayoutBuilder.single(SERVERS.PORT_0);
assertThat(client.bootstrapLayout(layout).get()).isEqualTo(true);
long epoch = layout.getEpoch();
assertThat(client.prepare(epoch, RANK_HIGH).get() != null).isEqualTo(true);
assertThatThrownBy(() -> {
client.prepare(epoch, RANK_LOW).get();
}).hasCauseInstanceOf(OutrankedException.class);
assertThatThrownBy(() -> {
client.prepare(epoch, 2L).get();
}).hasCauseInstanceOf(OutrankedException.class);
}
use of org.corfudb.runtime.view.Layout in project CorfuDB by CorfuDB.
the class LayoutServerTest method checkPhase1AndPhase2MessagesFromMultipleClients.
/**
* Validates that the layout server accept or rejects incoming phase1 and phase2 messages from multiple
* clients based on current state {Phease1Rank [rank, clientID], Phase2Rank [rank, clientID] }
* If LayoutServer has accepted a phase1 message from a client , it can only accept a higher ranked phase1 message
* from another client.
* A phase2 message can only be accepted if the last accepted phase1 message is from the same client and has the
* same rank.
*
* @throws Exception
*/
@Test
public void checkPhase1AndPhase2MessagesFromMultipleClients() throws Exception {
String serviceDir = PARAMETERS.TEST_TEMP_DIR;
LayoutServer s1 = getDefaultServer(serviceDir);
Layout layout = TestLayoutBuilder.single(SERVERS.PORT_0);
bootstrapServer(layout);
long newEpoch = layout.getEpoch() + 1;
Layout newLayout = TestLayoutBuilder.single(SERVERS.PORT_0);
newLayout.setEpoch(newEpoch);
setEpoch(newEpoch);
/* validate phase 1 */
sendPrepare(newEpoch, HIGH_RANK);
Assertions.assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.LAYOUT_PREPARE_ACK);
assertThat(s1).isPhase1Rank(new Rank(HIGH_RANK, AbstractServerTest.testClientId));
// message from a different client with same rank should be rejected or accepted based on
// whether the uuid is greater of smaller.
sendPrepare(UUID.nameUUIDFromBytes("OTHER_CLIENT".getBytes()), newEpoch, HIGH_RANK);
Assertions.assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.LAYOUT_PREPARE_REJECT);
sendPrepare(UUID.nameUUIDFromBytes("TEST_CLIENT_OTHER".getBytes()), newEpoch, HIGH_RANK);
Assertions.assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.LAYOUT_PREPARE_REJECT);
// message from a different client but with a higher rank gets accepted
sendPrepare(UUID.nameUUIDFromBytes("OTHER_CLIENT".getBytes()), newEpoch, HIGH_RANK + 1);
Assertions.assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.LAYOUT_PREPARE_ACK);
assertThat(s1).isPhase1Rank(new Rank(HIGH_RANK + 1, UUID.nameUUIDFromBytes("OTHER_CLIENT".getBytes())));
// testing behaviour after server restart
s1.shutdown();
LayoutServer s2 = getDefaultServer(serviceDir);
assertThat(s2).isInEpoch(newEpoch);
assertThat(s2).isPhase1Rank(new Rank(HIGH_RANK + 1, UUID.nameUUIDFromBytes("OTHER_CLIENT".getBytes())));
//duplicate message to be rejected
sendPrepare(UUID.nameUUIDFromBytes("OTHER_CLIENT".getBytes()), newEpoch, HIGH_RANK + 1);
Assertions.assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.LAYOUT_PREPARE_REJECT);
/* validate phase 2 */
//phase2 message from a different client than the one whose phase1 was last accepted is rejected
sendPropose(newEpoch, HIGH_RANK + 1, newLayout);
Assertions.assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.LAYOUT_PROPOSE_REJECT);
// phase2 from same client with same rank as in phase1 gets accepted
sendPropose(UUID.nameUUIDFromBytes("OTHER_CLIENT".getBytes()), newEpoch, HIGH_RANK + 1, newLayout);
Assertions.assertThat(getLastMessage().getMsgType()).isEqualTo(CorfuMsgType.ACK);
assertThat(s2).isInEpoch(newEpoch);
assertThat(s2).isPhase1Rank(new Rank(HIGH_RANK + 1, UUID.nameUUIDFromBytes("OTHER_CLIENT".getBytes())));
assertThat(s2).isPhase2Rank(new Rank(HIGH_RANK + 1, UUID.nameUUIDFromBytes("OTHER_CLIENT".getBytes())));
assertThat(s2).isProposedLayout(newLayout);
s2.shutdown();
}
Aggregations