Search in sources :

Example 6 with IStreamView

use of org.corfudb.runtime.view.stream.IStreamView in project CorfuDB by CorfuDB.

the class StreamViewTest method canReadWriteFromStreamWithoutBackpointers.

@Test
@SuppressWarnings("unchecked")
public void canReadWriteFromStreamWithoutBackpointers() throws Exception {
    r.setBackpointersDisabled(true);
    UUID streamA = UUID.nameUUIDFromBytes("stream A".getBytes());
    byte[] testPayload = "hello world".getBytes();
    IStreamView sv = r.getStreamsView().get(streamA);
    scheduleConcurrently(PARAMETERS.NUM_ITERATIONS_LOW, i -> sv.append(testPayload));
    executeScheduled(PARAMETERS.CONCURRENCY_SOME, PARAMETERS.TIMEOUT_NORMAL);
    scheduleConcurrently(PARAMETERS.NUM_ITERATIONS_LOW, i -> assertThat(sv.next().getPayload(getRuntime())).isEqualTo("hello world".getBytes()));
    executeScheduled(PARAMETERS.CONCURRENCY_SOME, PARAMETERS.TIMEOUT_NORMAL);
    assertThat(sv.next()).isEqualTo(null);
}
Also used : UUID(java.util.UUID) IStreamView(org.corfudb.runtime.view.stream.IStreamView) Test(org.junit.Test)

Example 7 with IStreamView

use of org.corfudb.runtime.view.stream.IStreamView in project CorfuDB by CorfuDB.

the class StreamViewTest method streamWillHoleFill.

@Test
@SuppressWarnings("unchecked")
public void streamWillHoleFill() throws Exception {
    //begin tests
    UUID streamA = CorfuRuntime.getStreamID("stream A");
    byte[] testPayload = "hello world".getBytes();
    // Generate a hole.
    r.getSequencerView().nextToken(Collections.singleton(streamA), 1);
    // Write to the stream, and read back. The hole should be filled.
    IStreamView sv = r.getStreamsView().get(streamA);
    sv.append(testPayload);
    assertThat(sv.next().getPayload(getRuntime())).isEqualTo("hello world".getBytes());
    assertThat(sv.next()).isEqualTo(null);
}
Also used : UUID(java.util.UUID) IStreamView(org.corfudb.runtime.view.stream.IStreamView) Test(org.junit.Test)

Example 8 with IStreamView

use of org.corfudb.runtime.view.stream.IStreamView 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 9 with IStreamView

use of org.corfudb.runtime.view.stream.IStreamView in project CorfuDB by CorfuDB.

the class LayoutViewTest method reconfigurationDuringDataOperations.

/**
     * Fail a server and reconfigure
     * while data operations are going on.
     * Details:
     * Start with a configuration of 3 servers SERVERS.PORT_0, SERVERS.PORT_1, SERVERS.PORT_2.
     * Perform data operations. Fail SERVERS.PORT_1 and reconfigure to have only SERVERS.PORT_0 and SERVERS.PORT_2.
     * Perform data operations while the reconfiguration is going on. The operations should
     * be stuck till the new configuration is chosen and then complete after that.
     * FIXME: We cannot failover the server with the primary sequencer yet.
     *
     * @throws Exception
     */
@Test
public void reconfigurationDuringDataOperations() throws Exception {
    addServer(SERVERS.PORT_0);
    addServer(SERVERS.PORT_1);
    addServer(SERVERS.PORT_2);
    Layout l = new TestLayoutBuilder().setEpoch(1L).addLayoutServer(SERVERS.PORT_0).addLayoutServer(SERVERS.PORT_1).addLayoutServer(SERVERS.PORT_2).addSequencer(SERVERS.PORT_0).addSequencer(SERVERS.PORT_1).addSequencer(SERVERS.PORT_2).buildSegment().buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_1).addLogUnit(SERVERS.PORT_2).addToSegment().addToLayout().build();
    bootstrapAllServers(l);
    CorfuRuntime corfuRuntime = getRuntime(l).connect();
    // Thread to reconfigure the layout
    CountDownLatch startReconfigurationLatch = new CountDownLatch(1);
    CountDownLatch layoutReconfiguredLatch = new CountDownLatch(1);
    Thread t = new Thread(() -> {
        try {
            startReconfigurationLatch.await();
            corfuRuntime.invalidateLayout();
            // Fail the network link between the client and test server
            addServerRule(SERVERS.PORT_1, new TestRule().always().drop());
            // New layout removes the failed server SERVERS.PORT_0
            Layout newLayout = new TestLayoutBuilder().setEpoch(l.getEpoch() + 1).addLayoutServer(SERVERS.PORT_0).addLayoutServer(SERVERS.PORT_2).addSequencer(SERVERS.PORT_0).addSequencer(SERVERS.PORT_2).buildSegment().buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_2).addToSegment().addToLayout().build();
            newLayout.setRuntime(corfuRuntime);
            //TODO need to figure out if we can move to
            //update layout
            newLayout.moveServersToEpoch();
            corfuRuntime.getLayoutView().updateLayout(newLayout, newLayout.getEpoch());
            corfuRuntime.invalidateLayout();
            log.debug("layout updated new layout {}", corfuRuntime.getLayoutView().getLayout());
            layoutReconfiguredLatch.countDown();
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
    t.start();
    // verify writes and reads happen before and after the reconfiguration
    IStreamView sv = corfuRuntime.getStreamsView().get(CorfuRuntime.getStreamID("streamA"));
    // This append will happen before the reconfiguration while the read for this append
    // will happen after reconfiguration
    writeAndReadStream(corfuRuntime, sv, startReconfigurationLatch, layoutReconfiguredLatch);
    // Write and read after reconfiguration.
    writeAndReadStream(corfuRuntime, sv, startReconfigurationLatch, layoutReconfiguredLatch);
    t.join();
}
Also used : TestRule(org.corfudb.runtime.clients.TestRule) TestLayoutBuilder(org.corfudb.infrastructure.TestLayoutBuilder) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) CountDownLatch(java.util.concurrent.CountDownLatch) IStreamView(org.corfudb.runtime.view.stream.IStreamView) Test(org.junit.Test)

Example 10 with IStreamView

use of org.corfudb.runtime.view.stream.IStreamView in project CorfuDB by CorfuDB.

the class ObjectsViewTest method unrelatedStreamDoesNotConflict.

@Test
@SuppressWarnings("unchecked")
public void unrelatedStreamDoesNotConflict() throws Exception {
    //begin tests
    CorfuRuntime r = getDefaultRuntime();
    Map<String, String> smrMap = r.getObjectsView().build().setStreamName("map a").setTypeToken(new TypeToken<SMRMap<String, String>>() {
    }).open();
    IStreamView streamB = r.getStreamsView().get(CorfuRuntime.getStreamID("b"));
    smrMap.put("a", "b");
    streamB.append(new SMREntry("hi", new Object[] { "hello" }, Serializers.PRIMITIVE));
    //this TX should not conflict
    assertThat(smrMap).doesNotContainKey("b");
    r.getObjectsView().TXBegin();
    String b = smrMap.get("a");
    smrMap.put("b", b);
    r.getObjectsView().TXEnd();
    assertThat(smrMap).containsEntry("b", "b");
}
Also used : MultiSMREntry(org.corfudb.protocols.logprotocol.MultiSMREntry) SMREntry(org.corfudb.protocols.logprotocol.SMREntry) MultiObjectSMREntry(org.corfudb.protocols.logprotocol.MultiObjectSMREntry) TypeToken(com.google.common.reflect.TypeToken) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) IStreamView(org.corfudb.runtime.view.stream.IStreamView) Test(org.junit.Test)

Aggregations

IStreamView (org.corfudb.runtime.view.stream.IStreamView)19 Test (org.junit.Test)18 CorfuRuntime (org.corfudb.runtime.CorfuRuntime)11 UUID (java.util.UUID)10 MultiObjectSMREntry (org.corfudb.protocols.logprotocol.MultiObjectSMREntry)3 MultiSMREntry (org.corfudb.protocols.logprotocol.MultiSMREntry)3 SMREntry (org.corfudb.protocols.logprotocol.SMREntry)3 ILogData (org.corfudb.protocols.wireprotocol.ILogData)3 TypeToken (com.google.common.reflect.TypeToken)2 TestLayoutBuilder (org.corfudb.infrastructure.TestLayoutBuilder)2 TokenResponse (org.corfudb.protocols.wireprotocol.TokenResponse)2 Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Semaphore (java.util.concurrent.Semaphore)1 LogUnitServer (org.corfudb.infrastructure.LogUnitServer)1 TestRule (org.corfudb.runtime.clients.TestRule)1 SMRMap (org.corfudb.runtime.collections.SMRMap)1 AbstractViewTest (org.corfudb.runtime.view.AbstractViewTest)1