use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.
the class SealIT method RuntimeWithWrongEpochGetUpdated.
@Test
public void RuntimeWithWrongEpochGetUpdated() throws Exception {
Process corfuProcess = new CorfuServerRunner().setHost(corfuSingleNodeHost).setPort(corfuSingleNodePort).runServer();
CorfuRuntime cr1 = createDefaultRuntime();
CorfuRuntime cr2 = createDefaultRuntime();
Long beforeAddress = cr2.getSequencerView().nextToken(new HashSet<>(), 1).getToken().getTokenValue();
/* We will trigger a Paxos round, this is what will happen:
* 1. Set our layout (same than before) with a new Epoch
* 2. Seal the server(s)
* 3. Propose the new layout by driving paxos.
*/
Layout currentLayout = cr1.getLayoutView().getCurrentLayout();
/* 1 */
currentLayout.setEpoch(currentLayout.getEpoch() + 1);
/* 2 */
currentLayout.moveServersToEpoch();
/* 3 */
cr1.getLayoutView().updateLayout(currentLayout, 0);
/* Now cr2 is still stuck in the previous epoch. The next time it will ask for a token,
* emit a read or a write (msgs type that validate the epoch on the server side) it should
* receive a WrongEpochException. This exception is taken care of by the AbstractView class in
* the layoutHelper function.
*
* Upon receiving a wrong epoch, the new epoch will be set internally, and it will invalidate
* the layout.
*
* These steps get cr2 in the new epoch.
*/
Long afterAddress = cr2.getSequencerView().nextToken(new HashSet<>(), 1).getToken().getTokenValue();
assertThat(cr2.getLayoutView().getCurrentLayout().getEpoch()).isEqualTo(cr1.getLayoutView().getCurrentLayout().getEpoch());
assertThat(afterAddress).isEqualTo(beforeAddress + 1);
assertThat(shutdownCorfuServer(corfuProcess)).isTrue();
}
use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.
the class LogUnitClientTest method canReadWrite.
@Test
public void canReadWrite() throws Exception {
byte[] testString = "hello world".getBytes();
client.write(0, Collections.<UUID>emptySet(), null, testString, Collections.emptyMap()).get();
LogData r = client.read(0).get().getReadSet().get(0L);
assertThat(r.getType()).isEqualTo(DataType.DATA);
assertThat(r.getPayload(new CorfuRuntime())).isEqualTo(testString);
}
use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.
the class LogUnitClientTest method cannotOutrank.
@Test
public void cannotOutrank() throws ExecutionException, InterruptedException {
byte[] testString = "hello world".getBytes();
client.write(0, Collections.<UUID>emptySet(), new IMetadata.DataRank(2), testString, Collections.emptyMap()).get();
LogData r = client.read(0).get().getReadSet().get(0L);
assertThat(r.getType()).isEqualTo(DataType.DATA);
assertThat(r.getPayload(new CorfuRuntime())).isEqualTo(testString);
byte[] testString2 = "hello world 2".getBytes();
try {
client.write(0, Collections.<UUID>emptySet(), new IMetadata.DataRank(1), testString2, Collections.emptyMap()).get();
fail();
} catch (ExecutionException e) {
// expected
assertEquals(DataOutrankedException.class, e.getCause().getClass());
}
r = client.read(0).get().getReadSet().get(0L);
assertThat(r.getType()).isEqualTo(DataType.DATA);
assertThat(r.getPayload(new CorfuRuntime())).isEqualTo(testString);
}
use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.
the class LogUnitClientTest method canReadWriteRanked.
@Test
public void canReadWriteRanked() throws Exception {
byte[] testString = "hello world".getBytes();
client.write(0, Collections.<UUID>emptySet(), new IMetadata.DataRank(1), testString, Collections.emptyMap()).get();
LogData r = client.read(0).get().getReadSet().get(0L);
assertThat(r.getType()).isEqualTo(DataType.DATA);
assertThat(r.getPayload(new CorfuRuntime())).isEqualTo(testString);
byte[] testString2 = "hello world 2".getBytes();
client.write(0, Collections.<UUID>emptySet(), new IMetadata.DataRank(2), testString2, Collections.emptyMap()).get();
r = client.read(0).get().getReadSet().get(0L);
assertThat(r.getType()).isEqualTo(DataType.DATA);
assertThat(r.getPayload(new CorfuRuntime())).isEqualTo(testString2);
}
use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.
the class CorfuSMRObjectProxyTest method canUseCustomSerializer.
/** Disabled pending resolution of issue #285
@Test
public void deadLockTest() throws Exception {
CorfuRuntime runtime = getDefaultRuntime().connect();
Map<String, Integer> map =
runtime.getObjectsView()
.build()
.setStreamName("M")
.setType(SMRMap.class)
.open();
for(int x = 0; x < PARAMETERS.NUM_ITERATIONS_LOW; x++) {
// thread 1: update "a" and "b" atomically
Thread t1 = new Thread(() -> {
runtime.getObjectsView().TXBegin();
map.put("a", 1);
map.put("b", 1);
runtime.getObjectsView().TXEnd();
}
);
t1.start();
// thread 2: read "a", then "b"
Thread t2 = new Thread(() -> {
map.get("a");
map.get("b");
});
t2.start();
t1.join(PARAMETERS.TIMEOUT_NORMAL.toMillis());
t2.join(PARAMETERS.TIMEOUT_NORMAL.toMillis());
assertThat(t1.isAlive()).isFalse();
assertThat(t2.isAlive()).isFalse();
}
}
@Test
@SuppressWarnings("unchecked")
public void canUsePrimitiveSerializer()
throws Exception {
//begin tests
CorfuRuntime r = getDefaultRuntime().connect();
TestClassWithPrimitives test = r.getObjectsView().build()
.setType(TestClassWithPrimitives.class)
.setStreamName("test")
.setSerializer(Serializers.PRIMITIVE)
.open();
test.setPrimitive("hello world".getBytes());
assertThat(test.getPrimitive())
.isEqualTo("hello world".getBytes());
}
**/
@Test
@SuppressWarnings("unchecked")
public void canUseCustomSerializer() throws Exception {
//Register a custom serializer and use it with an SMR object
ISerializer customSerializer = new CustomSerializer((byte) (Serializers.SYSTEM_SERIALIZERS_COUNT + 1));
Serializers.registerSerializer(customSerializer);
CorfuRuntime r = getDefaultRuntime();
Map<String, String> test = r.getObjectsView().build().setType(SMRMap.class).setStreamName("test").setSerializer(customSerializer).open();
test.put("a", "b");
test.get("a");
assertThat(test.get("a")).isEqualTo("b");
}
Aggregations