Search in sources :

Example 6 with TestLayoutBuilder

use of org.corfudb.infrastructure.TestLayoutBuilder in project CorfuDB by CorfuDB.

the class AddressSpaceViewTest method ensureStripingReadAllWorks.

@Test
@SuppressWarnings("unchecked")
public void ensureStripingReadAllWorks() throws Exception {
    addServer(SERVERS.PORT_0);
    addServer(SERVERS.PORT_1);
    addServer(SERVERS.PORT_2);
    bootstrapAllServers(new TestLayoutBuilder().setEpoch(1L).addLayoutServer(SERVERS.PORT_0).addSequencer(SERVERS.PORT_0).buildSegment().buildStripe().addLogUnit(SERVERS.PORT_0).addToSegment().buildStripe().addLogUnit(SERVERS.PORT_1).addToSegment().buildStripe().addLogUnit(SERVERS.PORT_2).addToSegment().addToLayout().build());
    //configure the layout accordingly
    CorfuRuntime r = getRuntime().connect();
    UUID streamA = UUID.nameUUIDFromBytes("stream A".getBytes());
    byte[] testPayload = "hello world".getBytes();
    final long ADDRESS_0 = 0;
    final long ADDRESS_1 = 1;
    final long ADDRESS_2 = 3;
    Token token = new Token(ADDRESS_0, r.getLayoutView().getLayout().getEpoch());
    r.getAddressSpaceView().write(token, testPayload);
    assertThat(r.getAddressSpaceView().read(ADDRESS_0).getPayload(getRuntime())).isEqualTo("hello world".getBytes());
    r.getAddressSpaceView().write(new Token(ADDRESS_1, r.getLayoutView().getLayout().getEpoch()), "1".getBytes());
    r.getAddressSpaceView().write(new Token(ADDRESS_2, r.getLayoutView().getLayout().getEpoch()), "3".getBytes());
    List<Long> rs = new ArrayList<>();
    rs.add(ADDRESS_0);
    rs.add(ADDRESS_1);
    rs.add(ADDRESS_2);
    Map<Long, ILogData> m = r.getAddressSpaceView().read(rs);
    assertThat(m.get(ADDRESS_0).getPayload(getRuntime())).isEqualTo("hello world".getBytes());
    assertThat(m.get(ADDRESS_1).getPayload(getRuntime())).isEqualTo("1".getBytes());
    assertThat(m.get(ADDRESS_2).getPayload(getRuntime())).isEqualTo("3".getBytes());
}
Also used : TestLayoutBuilder(org.corfudb.infrastructure.TestLayoutBuilder) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test)

Example 7 with TestLayoutBuilder

use of org.corfudb.infrastructure.TestLayoutBuilder in project CorfuDB by CorfuDB.

the class AddressSpaceViewTest method ensureStripingWorks.

@Test
@SuppressWarnings("unchecked")
public void ensureStripingWorks() throws Exception {
    addServer(SERVERS.PORT_0);
    addServer(SERVERS.PORT_1);
    addServer(SERVERS.PORT_2);
    //configure the layout accordingly
    bootstrapAllServers(new TestLayoutBuilder().setEpoch(1L).addLayoutServer(SERVERS.PORT_0).addSequencer(SERVERS.PORT_0).buildSegment().buildStripe().addLogUnit(SERVERS.PORT_0).addToSegment().buildStripe().addLogUnit(SERVERS.PORT_1).addToSegment().buildStripe().addLogUnit(SERVERS.PORT_2).addToSegment().addToLayout().build());
    CorfuRuntime r = getRuntime().connect();
    UUID streamA = UUID.nameUUIDFromBytes("stream A".getBytes());
    byte[] testPayload = "hello world".getBytes();
    final long epoch = r.getLayoutView().getLayout().getEpoch();
    r.getAddressSpaceView().write(new TokenResponse(0, epoch, Collections.singletonMap(streamA, Address.NO_BACKPOINTER)), "hello world".getBytes());
    assertThat(r.getAddressSpaceView().read(0L).getPayload(getRuntime())).isEqualTo("hello world".getBytes());
    assertThat(r.getAddressSpaceView().read(0L).containsStream(streamA)).isTrue();
    // Ensure that the data was written to each logunit.
    LogUnitServerAssertions.assertThat(getLogUnit(SERVERS.PORT_0)).matchesDataAtAddress(0, testPayload);
    LogUnitServerAssertions.assertThat(getLogUnit(SERVERS.PORT_1)).isEmptyAtAddress(0);
    LogUnitServerAssertions.assertThat(getLogUnit(SERVERS.PORT_2)).isEmptyAtAddress(0);
    r.getAddressSpaceView().write(new TokenResponse(1, epoch, Collections.singletonMap(streamA, Address.NO_BACKPOINTER)), "1".getBytes());
    LogUnitServerAssertions.assertThat(getLogUnit(SERVERS.PORT_0)).matchesDataAtAddress(0, testPayload);
    LogUnitServerAssertions.assertThat(getLogUnit(SERVERS.PORT_1)).matchesDataAtAddress(1, "1".getBytes());
    LogUnitServerAssertions.assertThat(getLogUnit(SERVERS.PORT_2)).isEmptyAtAddress(0);
}
Also used : TestLayoutBuilder(org.corfudb.infrastructure.TestLayoutBuilder) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test)

Example 8 with TestLayoutBuilder

use of org.corfudb.infrastructure.TestLayoutBuilder in project CorfuDB by CorfuDB.

the class ChainReplicationViewTest method ensureAllUnitsContainData.

@Test
@SuppressWarnings("unchecked")
public void ensureAllUnitsContainData() throws Exception {
    addServer(SERVERS.PORT_0);
    addServer(SERVERS.PORT_1);
    addServer(SERVERS.PORT_2);
    bootstrapAllServers(new TestLayoutBuilder().addLayoutServer(SERVERS.PORT_0).addSequencer(SERVERS.PORT_0).buildSegment().setReplicationMode(Layout.ReplicationMode.CHAIN_REPLICATION).buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_1).addLogUnit(SERVERS.PORT_2).addToSegment().addToLayout().build());
    //configure the layout accordingly
    CorfuRuntime r = getRuntime().connect();
    UUID streamA = UUID.nameUUIDFromBytes("stream A".getBytes());
    byte[] testPayload = "hello world".getBytes();
    r.getAddressSpaceView().write(new TokenResponse(0, 0, Collections.singletonMap(streamA, Address.NO_BACKPOINTER)), testPayload);
    assertThat(r.getAddressSpaceView().read(0L).getPayload(getRuntime())).isEqualTo("hello world".getBytes());
    assertThat(r.getAddressSpaceView().read(0L).containsStream(streamA));
    // Ensure that the data was written to each logunit.
    assertThat(getLogUnit(SERVERS.PORT_0)).matchesDataAtAddress(0, testPayload);
    assertThat(getLogUnit(SERVERS.PORT_1)).matchesDataAtAddress(0, testPayload);
    assertThat(getLogUnit(SERVERS.PORT_2)).matchesDataAtAddress(0, testPayload);
}
Also used : TestLayoutBuilder(org.corfudb.infrastructure.TestLayoutBuilder) TokenResponse(org.corfudb.protocols.wireprotocol.TokenResponse) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) UUID(java.util.UUID) Test(org.junit.Test)

Example 9 with TestLayoutBuilder

use of org.corfudb.infrastructure.TestLayoutBuilder in project CorfuDB by CorfuDB.

the class ChainReplicationViewTest method canReadWriteToMultiple.

@Test
@SuppressWarnings("unchecked")
public void canReadWriteToMultiple() throws Exception {
    addServer(SERVERS.PORT_0);
    addServer(SERVERS.PORT_1);
    addServer(SERVERS.PORT_2);
    bootstrapAllServers(new TestLayoutBuilder().addLayoutServer(SERVERS.PORT_0).addSequencer(SERVERS.PORT_0).buildSegment().setReplicationMode(Layout.ReplicationMode.CHAIN_REPLICATION).buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_1).addLogUnit(SERVERS.PORT_2).addToSegment().addToLayout().build());
    //configure the layout accordingly
    CorfuRuntime r = getRuntime().connect();
    UUID streamA = UUID.nameUUIDFromBytes("stream A".getBytes());
    byte[] testPayload = "hello world".getBytes();
    r.getAddressSpaceView().write(new TokenResponse(0, runtime.getLayoutView().getLayout().getEpoch(), Collections.singletonMap(streamA, Address.NO_BACKPOINTER)), testPayload);
    assertThat(r.getAddressSpaceView().read(0L).getPayload(getRuntime())).isEqualTo("hello world".getBytes());
    assertThat(r.getAddressSpaceView().read(0L).containsStream(streamA)).isTrue();
}
Also used : TestLayoutBuilder(org.corfudb.infrastructure.TestLayoutBuilder) TokenResponse(org.corfudb.protocols.wireprotocol.TokenResponse) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) UUID(java.util.UUID) Test(org.junit.Test)

Example 10 with TestLayoutBuilder

use of org.corfudb.infrastructure.TestLayoutBuilder in project CorfuDB by CorfuDB.

the class LayoutSealTest method getLayout.

/**
     * Gets a layout with 5 Servers:
     * PORT_0, PORT_1, PORT_2, PORT_3, PORT_4
     * Sets the replication view as specified.
     *
     * @param replicationMode Replication view to set all segments in the layout with.
     * @return  Built layout with a connected runtime.
     */
public Layout getLayout(Layout.ReplicationMode replicationMode) {
    addServer(SERVERS.PORT_0);
    addServer(SERVERS.PORT_1);
    addServer(SERVERS.PORT_2);
    addServer(SERVERS.PORT_3);
    addServer(SERVERS.PORT_4);
    Layout l = new TestLayoutBuilder().setEpoch(1).addLayoutServer(SERVERS.PORT_0).addLayoutServer(SERVERS.PORT_1).addLayoutServer(SERVERS.PORT_2).addSequencer(SERVERS.PORT_0).buildSegment().setReplicationMode(replicationMode).buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_1).addLogUnit(SERVERS.PORT_2).addToSegment().buildStripe().addLogUnit(SERVERS.PORT_3).addLogUnit(SERVERS.PORT_4).addToSegment().addToLayout().build();
    bootstrapAllServers(l);
    CorfuRuntime corfuRuntime = getRuntime(l).connect();
    l.setRuntime(corfuRuntime);
    setAggressiveTimeouts(l);
    return l;
}
Also used : TestLayoutBuilder(org.corfudb.infrastructure.TestLayoutBuilder) CorfuRuntime(org.corfudb.runtime.CorfuRuntime)

Aggregations

TestLayoutBuilder (org.corfudb.infrastructure.TestLayoutBuilder)14 CorfuRuntime (org.corfudb.runtime.CorfuRuntime)12 Test (org.junit.Test)11 TestRule (org.corfudb.runtime.clients.TestRule)5 UUID (java.util.UUID)4 TokenResponse (org.corfudb.protocols.wireprotocol.TokenResponse)4 IStreamView (org.corfudb.runtime.view.stream.IStreamView)4 PurgeFailurePolicy (org.corfudb.infrastructure.PurgeFailurePolicy)3 ServerContext (org.corfudb.infrastructure.ServerContext)3 ServerContextBuilder (org.corfudb.infrastructure.ServerContextBuilder)3 TestServerRouter (org.corfudb.infrastructure.TestServerRouter)3 TypeToken (com.google.common.reflect.TypeToken)2 Collections (java.util.Collections)2 Map (java.util.Map)2 Semaphore (java.util.concurrent.Semaphore)2 TimeUnit (java.util.concurrent.TimeUnit)2 Getter (lombok.Getter)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 CorfuMsgType (org.corfudb.protocols.wireprotocol.CorfuMsgType)2 ManagementClient (org.corfudb.runtime.clients.ManagementClient)2