Package com.datastax.driver.core.policies

Examples of com.datastax.driver.core.policies.ExponentialReconnectionPolicy$ExponentialSchedule


    /*
     * Test the ExponentialReconnectionPolicy.
     */
    @Test(groups = "long")
    public void exponentialReconnectionPolicyTest() throws Throwable {
        Cluster.Builder builder = Cluster.builder().withReconnectionPolicy(new ExponentialReconnectionPolicy(2 * 1000, 5 * 60 * 1000));

        // Ensure that ExponentialReconnectionPolicy is what we should be testing
        if (!(builder.getConfiguration().getPolicies().getReconnectionPolicy() instanceof ExponentialReconnectionPolicy)) {
            fail("Set policy does not match retrieved policy.");
        }

        // Test basic getters
        ExponentialReconnectionPolicy reconnectionPolicy = (ExponentialReconnectionPolicy) builder.getConfiguration().getPolicies().getReconnectionPolicy();
        assertTrue(reconnectionPolicy.getBaseDelayMs() == 2 * 1000);
        assertTrue(reconnectionPolicy.getMaxDelayMs() == 5 * 60 * 1000);

        // Test erroneous instantiations
        try {
            new ExponentialReconnectionPolicy(-1, 1);
            fail();
        } catch (IllegalArgumentException e) {}

        try {
            new ExponentialReconnectionPolicy(1, -1);
            fail();
        } catch (IllegalArgumentException e) {}

        try {
            new ExponentialReconnectionPolicy(-1, -1);
            fail();
        } catch (IllegalArgumentException e) {}

        try {
            new ExponentialReconnectionPolicy(2, 1);
            fail();
        } catch (IllegalArgumentException e) {}

        // Test nextDelays()
        ReconnectionPolicy.ReconnectionSchedule schedule = new ExponentialReconnectionPolicy(2 * 1000, 5 * 60 * 1000).newSchedule();
        assertTrue(schedule.nextDelayMs() == 2000);
        assertTrue(schedule.nextDelayMs() == 4000);
        assertTrue(schedule.nextDelayMs() == 8000);
        assertTrue(schedule.nextDelayMs() == 16000);
        assertTrue(schedule.nextDelayMs() == 32000);
        for (int i = 0; i < 64; ++i)
            schedule.nextDelayMs();
        assertTrue(schedule.nextDelayMs() == reconnectionPolicy.getMaxDelayMs());

        // Run integration test
        long restartTime = 2 + 4 + 8 + 2;   // 16: 3 full cycles + 2 seconds
        long retryTime = 30;                // 4th cycle start time
        long breakTime = 62;                // time until next reconnection attempt
View Full Code Here


    public CassandraSession create()
    {
        Cluster.Builder clusterBuilder = Cluster.builder();
        clusterBuilder.addContactPoints(contactPoints.toArray(new String[contactPoints.size()]));
        clusterBuilder.withPort(nativeProtocolPort);
        clusterBuilder.withReconnectionPolicy(new ExponentialReconnectionPolicy(500, 10000));

        QueryOptions options = new QueryOptions();
        options.setFetchSize(fetchSize);
        options.setConsistencyLevel(consistencyLevel);
        clusterBuilder.withQueryOptions(options);
View Full Code Here

        List<String> contactPoints = checkNotNull(config.getContactPoints(), "contactPoints is null");
        checkArgument(!contactPoints.isEmpty(), "empty contactPoints");
        clusterBuilder.addContactPoints(contactPoints.toArray(new String[contactPoints.size()]));

        clusterBuilder.withPort(config.getNativeProtocolPort());
        clusterBuilder.withReconnectionPolicy(new ExponentialReconnectionPolicy(500, 10000));

        SocketOptions socketOptions = new SocketOptions();
        socketOptions.setReadTimeoutMillis(config.getClientReadTimeout());
        socketOptions.setConnectTimeoutMillis(config.getClientConnectTimeout());
        if (config.getClientSoLinger() != null) {
View Full Code Here

        List<String> contactPoints = checkNotNull(config.getContactPoints(), "contactPoints is null");
        checkArgument(!contactPoints.isEmpty(), "empty contactPoints");
        clusterBuilder.addContactPoints(contactPoints.toArray(new String[contactPoints.size()]));

        clusterBuilder.withPort(config.getNativeProtocolPort());
        clusterBuilder.withReconnectionPolicy(new ExponentialReconnectionPolicy(500, 10000));

        SocketOptions socketOptions = new SocketOptions();
        socketOptions.setReadTimeoutMillis(config.getClientReadTimeout());
        socketOptions.setConnectTimeoutMillis(config.getClientConnectTimeout());
        if (config.getClientSoLinger() != null) {
View Full Code Here

        List<String> contactPoints = checkNotNull(config.getContactPoints(), "contactPoints is null");
        checkArgument(!contactPoints.isEmpty(), "empty contactPoints");
        clusterBuilder.addContactPoints(contactPoints.toArray(new String[contactPoints.size()]));

        clusterBuilder.withPort(config.getNativeProtocolPort());
        clusterBuilder.withReconnectionPolicy(new ExponentialReconnectionPolicy(500, 10000));
        clusterBuilder.withRetryPolicy(config.getRetryPolicy().getPolicy());

        SocketOptions socketOptions = new SocketOptions();
        socketOptions.setReadTimeoutMillis(Ints.checkedCast(config.getClientReadTimeout().toMillis()));
        socketOptions.setConnectTimeoutMillis(Ints.checkedCast(config.getClientConnectTimeout().toMillis()));
View Full Code Here

        List<String> contactPoints = checkNotNull(config.getContactPoints(), "contactPoints is null");
        checkArgument(!contactPoints.isEmpty(), "empty contactPoints");
        clusterBuilder.addContactPoints(contactPoints.toArray(new String[contactPoints.size()]));

        clusterBuilder.withPort(config.getNativeProtocolPort());
        clusterBuilder.withReconnectionPolicy(new ExponentialReconnectionPolicy(500, 10000));

        SocketOptions socketOptions = new SocketOptions();
        socketOptions.setReadTimeoutMillis(config.getClientReadTimeout());
        socketOptions.setConnectTimeoutMillis(config.getClientConnectTimeout());
        if (config.getClientSoLinger() != null) {
View Full Code Here

            String maxDelayMsAsStr = props.getProperty("maxDelayMs");
            if (!StringUtils.isBlank(baseDelayMsAsStr) && !StringUtils.isBlank(maxDelayMsAsStr))
            {
                long baseDelayMs = new Long(baseDelayMsAsStr);
                long maxDelayMs = new Long(maxDelayMsAsStr);
                reconnectionPolicy = new ExponentialReconnectionPolicy(baseDelayMs, maxDelayMs);
            }
            break;

        default:
            break;
View Full Code Here

TOP

Related Classes of com.datastax.driver.core.policies.ExponentialReconnectionPolicy$ExponentialSchedule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.