Search in sources :

Example 11 with ILogData

use of org.corfudb.protocols.wireprotocol.ILogData in project CorfuDB by CorfuDB.

the class ChainReplicationProtocolTest method failedWriteCanBeRead.

/** Check to see that a read correctly
     * completes a failed write from another client.
     */
@Test
public void failedWriteCanBeRead() throws Exception {
    setupNodes();
    //begin tests
    final CorfuRuntime r = getDefaultRuntime();
    final IReplicationProtocol rp = getProtocol();
    final Layout layout = r.getLayoutView().getLayout();
    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);
    // At this point, a read
    // reflect the -other- clients value
    ILogData readResult = rp.read(layout, 0);
    assertThat(readResult.getPayload(r)).isEqualTo("incomplete".getBytes());
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) LogUnitClient(org.corfudb.runtime.clients.LogUnitClient) Layout(org.corfudb.runtime.view.Layout) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test)

Example 12 with ILogData

use of org.corfudb.protocols.wireprotocol.ILogData in project CorfuDB by CorfuDB.

the class AddressSpaceView method write.

/** Write the given log data using a token, returning
     * either when the write has been completed successfully,
     * or throwing an OverwriteException if another value
     * has been adopted, or a WrongEpochException if the
     * token epoch is invalid.
     *
     * @param token     The token to use for the write.
     * @param data      The data to write.
     * @throws OverwriteException   If the globalAddress given
     *                              by the token has adopted
     *                              another value.
     * @throws WrongEpochException  If the token epoch is invalid.
     */
public void write(IToken token, Object data) throws OverwriteException {
    final ILogData ld = new LogData(DataType.DATA, data);
    layoutHelper(l -> {
        if (token.getEpoch() != l.getEpoch()) {
            throw new WrongEpochException(l.getEpoch());
        }
        ld.useToken(token);
        l.getReplicationMode(token.getTokenValue()).getReplicationProtocol(runtime).write(l, ld);
        return null;
    });
    // Cache the successful write
    if (!runtime.isCacheDisabled()) {
        readCache.put(token.getTokenValue(), ld);
    }
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData) WrongEpochException(org.corfudb.runtime.exceptions.WrongEpochException)

Example 13 with ILogData

use of org.corfudb.protocols.wireprotocol.ILogData in project CorfuDB by CorfuDB.

the class StreamIT method simpleStreamTest.

//    @Test
public void simpleStreamTest() throws Exception {
    Process corfuServerProcess = new CorfuServerRunner().setHost(corfuSingleNodeHost).setPort(corfuSingleNodePort).runServer();
    CorfuRuntime rt = createDefaultRuntime();
    rt.setCacheDisabled(true);
    Random rand = new Random();
    UUID streamId = CorfuRuntime.getStreamID(Integer.toString(rand.nextInt()));
    IStreamView s1 = rt.getStreamsView().get(streamId);
    // Verify that the stream is empty
    assertThat(s1.hasNext()).isFalse();
    // Generate and append random data
    int entrySize = Integer.valueOf(PROPERTIES.getProperty("largeEntrySize"));
    final int numEntries = 100;
    byte[][] data = new byte[numEntries][entrySize];
    for (int x = 0; x < numEntries; x++) {
        rand.nextBytes(data[x]);
        s1.append(data[x]);
    }
    // Read back the data and verify it is correct
    for (int x = 0; x < numEntries; x++) {
        ILogData entry = s1.nextUpTo(x);
        byte[] tmp = (byte[]) entry.getPayload(rt);
        assertThat(tmp).isEqualTo(data[x]);
    }
    assertThat(shutdownCorfuServer(corfuServerProcess)).isTrue();
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) Random(java.util.Random) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) UUID(java.util.UUID) IStreamView(org.corfudb.runtime.view.stream.IStreamView)

Example 14 with ILogData

use of org.corfudb.protocols.wireprotocol.ILogData in project CorfuDB by CorfuDB.

the class LogUnitClientTest method createEmptyData.

private ILogData.SerializationHandle createEmptyData(long position, DataType type, IMetadata.DataRank rank) {
    ILogData data = new LogData(type);
    data.setRank(rank);
    data.setGlobalAddress(position);
    return data.getSerializedForm();
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) ILogData(org.corfudb.protocols.wireprotocol.ILogData) LogData(org.corfudb.protocols.wireprotocol.LogData)

Example 15 with ILogData

use of org.corfudb.protocols.wireprotocol.ILogData in project CorfuDB by CorfuDB.

the class AbstractTransactionContextTest method ensureEmptyWriteSetIsNotWritten.

/** Ensure that empty write sets are not written to the log.
     * This test applies to all contexts which is why it is in
     * the abstract test.
     */
@Test
public void ensureEmptyWriteSetIsNotWritten() {
    TXBegin();
    long result = getRuntime().getObjectsView().TXEnd();
    ILogData ld = getRuntime().getAddressSpaceView().peek(0);
    assertThat(ld).isNull();
    assertThat(result).isEqualTo(AbstractTransactionalContext.NOWRITE_ADDRESS);
}
Also used : ILogData(org.corfudb.protocols.wireprotocol.ILogData) Test(org.junit.Test)

Aggregations

ILogData (org.corfudb.protocols.wireprotocol.ILogData)27 LogData (org.corfudb.protocols.wireprotocol.LogData)9 Test (org.junit.Test)9 CorfuRuntime (org.corfudb.runtime.CorfuRuntime)8 Layout (org.corfudb.runtime.view.Layout)4 UUID (java.util.UUID)3 Nonnull (javax.annotation.Nonnull)3 SMREntry (org.corfudb.protocols.logprotocol.SMREntry)3 ReadResponse (org.corfudb.protocols.wireprotocol.ReadResponse)3 OverwriteException (org.corfudb.runtime.exceptions.OverwriteException)3 QuorumUnreachableException (org.corfudb.runtime.exceptions.QuorumUnreachableException)3 AbstractViewTest (org.corfudb.runtime.view.AbstractViewTest)3 QuorumFuturesFactory (org.corfudb.runtime.view.QuorumFuturesFactory)3 IStreamView (org.corfudb.runtime.view.stream.IStreamView)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 MultiObjectSMREntry (org.corfudb.protocols.logprotocol.MultiObjectSMREntry)2 MultiSMREntry (org.corfudb.protocols.logprotocol.MultiSMREntry)2 IMetadata (org.corfudb.protocols.wireprotocol.IMetadata)2 LogUnitClient (org.corfudb.runtime.clients.LogUnitClient)2 DataOutrankedException (org.corfudb.runtime.exceptions.DataOutrankedException)2