Search in sources :

Example 66 with CorfuRuntime

use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.

the class QuorumReplicationProtocolAdditionalTests method before.

@Before
public void before() {
    addServer(SERVERS.PORT_0);
    addServer(SERVERS.PORT_1);
    addServer(SERVERS.PORT_2);
    layout = new TestLayoutBuilder().setEpoch(1L).addLayoutServer(SERVERS.PORT_0).addLayoutServer(SERVERS.PORT_1).addLayoutServer(SERVERS.PORT_2).addSequencer(SERVERS.PORT_0).buildSegment().setReplicationMode(Layout.ReplicationMode.QUORUM_REPLICATION).buildStripe().addLogUnit(SERVERS.PORT_0).addLogUnit(SERVERS.PORT_1).addLogUnit(SERVERS.PORT_2).addToSegment().addToLayout().build();
    bootstrapAllServers(layout);
    getManagementServer(SERVERS.PORT_0).shutdown();
    getManagementServer(SERVERS.PORT_1).shutdown();
    getManagementServer(SERVERS.PORT_2).shutdown();
    layout.getSegment(0L).setReplicationMode(Layout.ReplicationMode.QUORUM_REPLICATION);
    corfuRuntime = new CorfuRuntime();
    corfuRuntime.setCacheDisabled(true);
    layout.getLayoutServers().forEach(corfuRuntime::addLayoutServer);
    layout.getAllServers().forEach(serverEndpoint -> {
        corfuRuntime.getRouter(serverEndpoint).setTimeoutConnect(PARAMETERS.TIMEOUT_VERY_SHORT.toMillis());
        corfuRuntime.getRouter(serverEndpoint).setTimeoutResponse(PARAMETERS.TIMEOUT_VERY_SHORT.toMillis());
        corfuRuntime.getRouter(serverEndpoint).setTimeoutRetry(PARAMETERS.TIMEOUT_VERY_SHORT.toMillis());
    });
    corfuRuntime.connect();
}
Also used : TestLayoutBuilder(org.corfudb.infrastructure.TestLayoutBuilder) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Before(org.junit.Before)

Example 67 with CorfuRuntime

use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.

the class BackpointerStreamViewTest method testGetHasNext.

/**
     * Tests the hasNext functionality of the streamView.
     */
@Test
public void testGetHasNext() {
    addServer(SERVERS.PORT_0);
    Layout layout = TestLayoutBuilder.single(SERVERS.PORT_0);
    bootstrapAllServers(layout);
    CorfuRuntime runtime = getRuntime(layout).connect();
    IStreamView sv = runtime.getStreamsView().get(CorfuRuntime.getStreamID("streamA"));
    sv.append("hello world".getBytes());
    assertThat(sv.hasNext()).isTrue();
    sv.next();
    assertThat(sv.hasNext()).isFalse();
}
Also used : Layout(org.corfudb.runtime.view.Layout) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) Test(org.junit.Test) AbstractViewTest(org.corfudb.runtime.view.AbstractViewTest)

Example 68 with CorfuRuntime

use of org.corfudb.runtime.CorfuRuntime in project CorfuDB by CorfuDB.

the class QCSMRobject method main.

public static String[] main(String[] args) {
    if (args != null && args.length > 0 && args[0].contentEquals("reboot")) {
        ManagementServer ms = CorfuServer.getManagementServer();
        ms.shutdown();
        CorfuServer.addManagementServer();
        LogUnitServer ls = CorfuServer.getLogUnitServer();
        if (ls != null) {
            ls.shutdown();
            CorfuServer.addLogUnit();
            return replyOk();
        } else {
            return replyErr("No active log server");
        }
    }
    // Parse the options given, using docopt.
    Map<String, Object> opts = new Docopt(USAGE).withVersion(GitRepositoryState.getRepositoryState().describe).parse(args);
    // Get a org.corfudb.runtime instance from the options.
    String config = (String) opts.get("--config");
    String qapp = (String) opts.get("--quickcheck-ap-prefix");
    String addressportPrefix = "";
    if (qapp != null) {
        addressportPrefix = qapp;
    }
    CorfuRuntime rt;
    if (rtMap.get(addressportPrefix + config) == null) {
        rt = configureRuntime(opts);
        rtMap.putIfAbsent(addressportPrefix + config, rt);
    }
    rt = (CorfuRuntime) rtMap.get(addressportPrefix + config);
    String argz = ((String) opts.get("<args>"));
    int arity;
    String[] split;
    if (argz == null) {
        split = new String[0];
        arity = 0;
    } else {
        split = argz.split(",");
        if (argz.charAt(argz.length() - 1) == ',') {
            arity = split.length + 1;
            String[] new_split = new String[arity];
            for (int i = 0; i < arity - 1; i++) {
                new_split[i] = split[i];
            }
            new_split[arity - 1] = "";
            split = new_split;
        } else {
            arity = split.length;
        }
    }
    // Attempt to open the object
    Class<?> cls;
    try {
        cls = Class.forName((String) opts.get("<class>"));
    } catch (ClassNotFoundException cnfe) {
        throw new RuntimeException(cnfe);
    }
    Object o = rt.getObjectsView().build().setStreamName((String) opts.get("--stream-id")).setType(cls).open();
    // Use reflection to find the method...
    Method m;
    try {
        m = Arrays.stream(cls.getDeclaredMethods()).filter(x -> x.getName().equals(opts.get("<method>"))).filter(x -> x.getParameterCount() == arity).findFirst().get();
    } catch (NoSuchElementException nsee) {
        return replyErr("Method " + opts.get("<method>") + " with " + arity + " arguments not found!");
    }
    if (m == null) {
        return replyErr("Method " + opts.get("<method>") + " with " + arity + " arguments not found!");
    }
    Object ret;
    final int c10 = 10, c50 = 50;
    for (int i = 0; i < c10; i++) {
        try {
            ret = m.invoke(o, split);
        } catch (InvocationTargetException e) {
            Throwable c = ExceptionUtils.getCause(e);
            if (c.getClass() == org.corfudb.runtime.exceptions.NetworkException.class && c.toString().matches(".*Disconnected endpoint.*")) {
                // caused by a disconnection with the remote endpoint.
                try {
                    Thread.sleep(c50);
                } catch (InterruptedException ie) {
                }
                ;
                continue;
            } else {
                return replyErr("exception", e.getClass().getSimpleName(), "stack: " + ExceptionUtils.getStackTrace(e), "cause: " + ExceptionUtils.getCause(e));
            }
        } catch (IllegalAccessException e) {
            return replyErr("exception", e.getClass().getSimpleName(), "stack: " + ExceptionUtils.getStackTrace(e));
        } catch (Exception e) {
            return replyErr("Exception on object: " + e, "stack: " + ExceptionUtils.getStackTrace(e), "cause: " + ExceptionUtils.getCause(e));
        }
        if (ret != null) {
            return replyOk(ret.toString());
        } else {
            return replyOk();
        }
    }
    return replyErr("Exhausted for loop retries");
}
Also used : QCUtil.replyErr(org.corfudb.util.quickcheck.QCUtil.replyErr) Arrays(java.util.Arrays) GitRepositoryState(org.corfudb.util.GitRepositoryState) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LogUnitServer(org.corfudb.infrastructure.LogUnitServer) Docopt(org.docopt.Docopt) QCUtil.replyOk(org.corfudb.util.quickcheck.QCUtil.replyOk) ManagementServer(org.corfudb.infrastructure.ManagementServer) InvocationTargetException(java.lang.reflect.InvocationTargetException) ExceptionUtils(org.codehaus.plexus.util.ExceptionUtils) Map(java.util.Map) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) CorfuServer(org.corfudb.infrastructure.CorfuServer) QCUtil.configureRuntime(org.corfudb.util.quickcheck.QCUtil.configureRuntime) NoSuchElementException(java.util.NoSuchElementException) Method(java.lang.reflect.Method) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchElementException(java.util.NoSuchElementException) ManagementServer(org.corfudb.infrastructure.ManagementServer) Docopt(org.docopt.Docopt) CorfuRuntime(org.corfudb.runtime.CorfuRuntime) LogUnitServer(org.corfudb.infrastructure.LogUnitServer) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

CorfuRuntime (org.corfudb.runtime.CorfuRuntime)68 Test (org.junit.Test)56 UUID (java.util.UUID)18 ILogData (org.corfudb.protocols.wireprotocol.ILogData)13 IStreamView (org.corfudb.runtime.view.stream.IStreamView)13 TestLayoutBuilder (org.corfudb.infrastructure.TestLayoutBuilder)12 TokenResponse (org.corfudb.protocols.wireprotocol.TokenResponse)11 AbstractViewTest (org.corfudb.runtime.view.AbstractViewTest)11 Layout (org.corfudb.runtime.view.Layout)10 TypeToken (com.google.common.reflect.TypeToken)9 LogData (org.corfudb.protocols.wireprotocol.LogData)9 TransactionAbortedException (org.corfudb.runtime.exceptions.TransactionAbortedException)6 Semaphore (java.util.concurrent.Semaphore)5 TestRule (org.corfudb.runtime.clients.TestRule)5 SMRMap (org.corfudb.runtime.collections.SMRMap)5 Map (java.util.Map)4 Token (org.corfudb.protocols.wireprotocol.Token)4 Collections (java.util.Collections)3 ExecutionException (java.util.concurrent.ExecutionException)3 TimeUnit (java.util.concurrent.TimeUnit)3