Search in sources :

Example 1 with FakeClusterManager

use of io.vertx.test.fakecluster.FakeClusterManager in project vert.x by eclipse.

the class CreateVertxTest method testCreateClusteredVertxAsyncDetectJoinFailure.

@Test
public void testCreateClusteredVertxAsyncDetectJoinFailure() {
    VertxOptions options = new VertxOptions().setClusterManager(new FakeClusterManager() {

        @Override
        public void join(Handler<AsyncResult<Void>> resultHandler) {
            resultHandler.handle(Future.failedFuture(new Exception("joinfailure")));
        }
    });
    clusteredVertx(options, ar -> {
        assertTrue(ar.failed());
        assertEquals("joinfailure", ar.cause().getMessage());
        testComplete();
    });
    await();
}
Also used : FakeClusterManager(io.vertx.test.fakecluster.FakeClusterManager) Test(org.junit.Test)

Example 2 with FakeClusterManager

use of io.vertx.test.fakecluster.FakeClusterManager in project vert.x by eclipse.

the class VertxOptionsTest method testOptions.

@Test
public void testOptions() {
    VertxOptions options = new VertxOptions();
    assertEquals(2 * Runtime.getRuntime().availableProcessors(), options.getEventLoopPoolSize());
    int rand = TestUtils.randomPositiveInt();
    assertEquals(options, options.setEventLoopPoolSize(rand));
    assertEquals(rand, options.getEventLoopPoolSize());
    try {
        options.setEventLoopPoolSize(0);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    assertEquals(20, options.getWorkerPoolSize());
    rand = TestUtils.randomPositiveInt();
    assertEquals(options, options.setWorkerPoolSize(rand));
    assertEquals(rand, options.getWorkerPoolSize());
    try {
        options.setWorkerPoolSize(0);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    assertEquals(20, options.getInternalBlockingPoolSize());
    rand = TestUtils.randomPositiveInt();
    assertEquals(options, options.setInternalBlockingPoolSize(rand));
    assertEquals(rand, options.getInternalBlockingPoolSize());
    try {
        options.setInternalBlockingPoolSize(0);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    assertFalse(options.isClustered());
    assertEquals(options, options.setClustered(true));
    assertTrue(options.isClustered());
    assertEquals(0, options.getClusterPort());
    assertEquals(options, options.setClusterPort(1234));
    assertEquals(1234, options.getClusterPort());
    try {
        options.setClusterPort(-1);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    try {
        options.setClusterPort(65536);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    assertEquals(-1, options.getClusterPublicPort());
    assertEquals(options, options.setClusterPublicPort(1234));
    assertEquals(1234, options.getClusterPublicPort());
    try {
        options.setClusterPublicPort(-1);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    try {
        options.setClusterPublicPort(65536);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    assertEquals("localhost", options.getClusterHost());
    String randString = TestUtils.randomUnicodeString(100);
    assertEquals(options, options.setClusterHost(randString));
    assertEquals(randString, options.getClusterHost());
    assertEquals(null, options.getClusterPublicHost());
    randString = TestUtils.randomUnicodeString(100);
    assertEquals(options, options.setClusterPublicHost(randString));
    assertEquals(randString, options.getClusterPublicHost());
    assertEquals(20000, options.getClusterPingInterval());
    long randomLong = TestUtils.randomPositiveLong();
    assertEquals(options, options.setClusterPingInterval(randomLong));
    assertEquals(randomLong, options.getClusterPingInterval());
    try {
        options.setClusterPingInterval(-1);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
        assertEquals(randomLong, options.getClusterPingInterval());
    }
    assertEquals(20000, options.getClusterPingReplyInterval());
    randomLong = TestUtils.randomPositiveLong();
    assertEquals(options, options.setClusterPingReplyInterval(randomLong));
    assertEquals(randomLong, options.getClusterPingReplyInterval());
    try {
        options.setClusterPingReplyInterval(-1);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
        assertEquals(randomLong, options.getClusterPingReplyInterval());
    }
    assertEquals(1000, options.getBlockedThreadCheckInterval());
    rand = TestUtils.randomPositiveInt();
    assertEquals(options, options.setBlockedThreadCheckInterval(rand));
    assertEquals(rand, options.getBlockedThreadCheckInterval());
    try {
        options.setBlockedThreadCheckInterval(0);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    // 2 seconds in nano seconds
    assertEquals(2000l * 1000000, options.getMaxEventLoopExecuteTime());
    rand = TestUtils.randomPositiveInt();
    assertEquals(options, options.setMaxEventLoopExecuteTime(rand));
    assertEquals(rand, options.getMaxEventLoopExecuteTime());
    try {
        options.setMaxEventLoopExecuteTime(0);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    // 1 minute in nano seconds
    assertEquals(1l * 60 * 1000 * 1000000, options.getMaxWorkerExecuteTime());
    rand = TestUtils.randomPositiveInt();
    assertEquals(options, options.setMaxWorkerExecuteTime(rand));
    assertEquals(rand, options.getMaxWorkerExecuteTime());
    try {
        options.setMaxWorkerExecuteTime(0);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    ClusterManager mgr = new FakeClusterManager();
    assertNull(options.getClusterManager());
    assertEquals(options, options.setClusterManager(mgr));
    assertSame(mgr, options.getClusterManager());
    assertFalse(options.isHAEnabled());
    assertEquals(options, options.setHAEnabled(true));
    assertTrue(options.isHAEnabled());
    rand = TestUtils.randomPositiveInt();
    assertEquals(1, options.getQuorumSize());
    assertEquals(options, options.setQuorumSize(rand));
    assertEquals(rand, options.getQuorumSize());
    try {
        options.setQuorumSize(0);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    try {
        options.setQuorumSize(-1);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    assertEquals(VertxOptions.DEFAULT_HA_GROUP, options.getHAGroup());
    randString = TestUtils.randomUnicodeString(100);
    assertEquals(options, options.setHAGroup(randString));
    assertEquals(randString, options.getHAGroup());
    try {
        options.setHAGroup(null);
        fail("Should throw exception");
    } catch (NullPointerException e) {
    // OK
    }
    assertNotNull(options.getMetricsOptions());
    try {
        options.setWarningExceptionTime(-1);
        fail("Should throw exception");
    } catch (IllegalArgumentException e) {
    // OK
    }
    assertEquals(options, options.setWarningExceptionTime(1000000000l));
    assertEquals(1000000000l, options.getWarningExceptionTime());
}
Also used : VertxOptions(io.vertx.core.VertxOptions) ClusterManager(io.vertx.core.spi.cluster.ClusterManager) FakeClusterManager(io.vertx.test.fakecluster.FakeClusterManager) FakeClusterManager(io.vertx.test.fakecluster.FakeClusterManager) Test(org.junit.Test)

Aggregations

FakeClusterManager (io.vertx.test.fakecluster.FakeClusterManager)2 Test (org.junit.Test)2 VertxOptions (io.vertx.core.VertxOptions)1 ClusterManager (io.vertx.core.spi.cluster.ClusterManager)1