Search in sources :

Example 76 with AtomicInteger

use of java.util.concurrent.atomic.AtomicInteger in project jetty.project by eclipse.

the class XmlConfigurationTest method testNewObject.

@Test
public void testNewObject() throws Exception {
    for (String configure : _configure) {
        TestConfiguration.VALUE = 71;
        Map<String, String> properties = new HashMap<>();
        properties.put("whatever", "xxx");
        URL url = XmlConfigurationTest.class.getClassLoader().getResource(configure);
        final AtomicInteger count = new AtomicInteger(0);
        XmlConfiguration configuration = new XmlConfiguration(url) {

            @Override
            public void initializeDefaults(Object object) {
                if (object instanceof TestConfiguration) {
                    count.incrementAndGet();
                    ((TestConfiguration) object).setNested(null);
                    ((TestConfiguration) object).setTestString("NEW DEFAULT");
                }
            }
        };
        configuration.getProperties().putAll(properties);
        TestConfiguration tc = (TestConfiguration) configuration.configure();
        assertEquals(3, count.get());
        assertEquals("NEW DEFAULT", tc.getTestString());
        assertEquals("nested", tc.getNested().getTestString());
        assertEquals("NEW DEFAULT", tc.getNested().getNested().getTestString());
        assertEquals("Set String", "SetValue", tc.testObject);
        assertEquals("Set Type", 2, tc.testInt);
        assertEquals(18080, tc.propValue);
        assertEquals("Put", "PutValue", tc.get("Test"));
        assertEquals("Put dft", "2", tc.get("TestDft"));
        assertEquals("Put type", 2, tc.get("TestInt"));
        assertEquals("Trim", "PutValue", tc.get("Trim"));
        assertEquals("Null", null, tc.get("Null"));
        assertEquals("NullTrim", null, tc.get("NullTrim"));
        assertEquals("ObjectTrim", 1.2345, tc.get("ObjectTrim"));
        assertEquals("Objects", "-1String", tc.get("Objects"));
        assertEquals("ObjectsTrim", "-1String", tc.get("ObjectsTrim"));
        assertEquals("String", "\n    PutValue\n  ", tc.get("String"));
        assertEquals("NullString", "", tc.get("NullString"));
        assertEquals("WhiteSpace", "\n  ", tc.get("WhiteSpace"));
        assertEquals("ObjectString", "\n    1.2345\n  ", tc.get("ObjectString"));
        assertEquals("ObjectsString", "-1String", tc.get("ObjectsString"));
        assertEquals("ObjectsWhiteString", "-1\n  String", tc.get("ObjectsWhiteString"));
        assertEquals("SystemProperty", System.getProperty("user.dir") + "/stuff", tc.get("SystemProperty"));
        assertEquals("Property", "xxx", tc.get("Property"));
        assertEquals("Called", "Yes", tc.get("Called"));
        assertTrue(TestConfiguration.called);
        assertEquals("oa[0]", "Blah", tc.oa[0]);
        assertEquals("oa[1]", "1.2.3.4:5678", tc.oa[1]);
        assertEquals("oa[2]", 1.2345, tc.oa[2]);
        assertEquals("oa[3]", null, tc.oa[3]);
        assertEquals("ia[0]", 1, tc.ia[0]);
        assertEquals("ia[1]", 2, tc.ia[1]);
        assertEquals("ia[2]", 3, tc.ia[2]);
        assertEquals("ia[3]", 0, tc.ia[3]);
        TestConfiguration tc2 = tc.nested;
        assertTrue(tc2 != null);
        assertEquals("Called(bool)", true, tc2.get("Arg"));
        assertEquals("nested config", null, tc.get("Arg"));
        assertEquals("nested config", true, tc2.get("Arg"));
        assertEquals("nested config", "Call1", tc2.testObject);
        assertEquals("nested config", 4, tc2.testInt);
        assertEquals("nested call", "http://www.eclipse.com/", tc2.url.toString());
        assertEquals("static to field", 71, tc.testField1);
        assertEquals("field to field", 2, tc.testField2);
        assertEquals("literal to static", 42, TestConfiguration.VALUE);
    }
}
Also used : HashMap(java.util.HashMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) URL(java.net.URL) Test(org.junit.Test)

Example 77 with AtomicInteger

use of java.util.concurrent.atomic.AtomicInteger in project vert.x by eclipse.

the class DeploymentTest method testCloseHooksCalled.

@Test
public void testCloseHooksCalled() throws Exception {
    AtomicInteger closedCount = new AtomicInteger();
    Closeable myCloseable1 = completionHandler -> {
        closedCount.incrementAndGet();
        completionHandler.handle(Future.succeededFuture());
    };
    Closeable myCloseable2 = completionHandler -> {
        closedCount.incrementAndGet();
        completionHandler.handle(Future.succeededFuture());
    };
    MyAsyncVerticle verticle = new MyAsyncVerticle(f -> {
        ContextImpl ctx = (ContextImpl) Vertx.currentContext();
        ctx.addCloseHook(myCloseable1);
        ctx.addCloseHook(myCloseable2);
        f.complete(null);
    }, f -> f.complete(null));
    vertx.deployVerticle(verticle, ar -> {
        assertTrue(ar.succeeded());
        assertEquals(0, closedCount.get());
        vertx.undeploy(ar.result(), ar2 -> {
            assertTrue(ar2.succeeded());
            assertEquals(2, closedCount.get());
            testComplete();
        });
    });
    await();
}
Also used : java.util(java.util) io.vertx.core(io.vertx.core) Files(java.nio.file.Files) URL(java.net.URL) io.vertx.core.impl(io.vertx.core.impl) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Message(io.vertx.core.eventbus.Message) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) JsonArray(io.vertx.core.json.JsonArray) CountDownLatch(java.util.concurrent.CountDownLatch) URLClassLoader(java.net.URLClassLoader) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompilingClassLoader(io.vertx.core.impl.verticle.CompilingClassLoader) JsonObject(io.vertx.core.json.JsonObject) SourceVerticle(io.vertx.test.core.sourceverticle.SourceVerticle) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 78 with AtomicInteger

use of java.util.concurrent.atomic.AtomicInteger in project vert.x by eclipse.

the class EventBusFlowControlTest method testFlowControlPauseConsumer.

@Test
public void testFlowControlPauseConsumer() {
    MessageProducer<String> prod = eb.sender("some-address");
    int numBatches = 10;
    int wqms = 100;
    prod.setWriteQueueMaxSize(wqms);
    MessageConsumer<String> consumer = eb.consumer("some-address");
    AtomicInteger cnt = new AtomicInteger();
    AtomicBoolean paused = new AtomicBoolean();
    consumer.handler(msg -> {
        assertFalse(paused.get());
        int c = cnt.incrementAndGet();
        if (c == numBatches * wqms) {
            testComplete();
        }
        if (c % 100 == 0) {
            consumer.pause();
            paused.set(true);
            vertx.setTimer(100, tid -> {
                paused.set(false);
                consumer.resume();
            });
        }
    });
    sendBatch(prod, wqms, numBatches, 0);
    await();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 79 with AtomicInteger

use of java.util.concurrent.atomic.AtomicInteger in project vert.x by eclipse.

the class EventBusFlowControlTest method testFlowControl.

@Test
public void testFlowControl() {
    MessageProducer<String> prod = eb.sender("some-address");
    int numBatches = 1000;
    int wqms = 2000;
    prod.setWriteQueueMaxSize(wqms);
    MessageConsumer<String> consumer = eb.consumer("some-address");
    AtomicInteger cnt = new AtomicInteger();
    consumer.handler(msg -> {
        int c = cnt.incrementAndGet();
        if (c == numBatches * wqms) {
            testComplete();
        }
    });
    vertx.runOnContext(v -> {
        sendBatch(prod, wqms, numBatches, 0);
    });
    await();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test)

Example 80 with AtomicInteger

use of java.util.concurrent.atomic.AtomicInteger in project vert.x by eclipse.

the class EventBusFlowControlTest method testFlowControlWithOptions.

@Test
public void testFlowControlWithOptions() {
    MessageProducer<String> prod = eb.sender("some-address");
    prod.deliveryOptions(new DeliveryOptions().addHeader("foo", "bar"));
    int numBatches = 1000;
    int wqms = 2000;
    prod.setWriteQueueMaxSize(wqms);
    MessageConsumer<String> consumer = eb.consumer("some-address");
    AtomicInteger cnt = new AtomicInteger();
    consumer.handler(msg -> {
        int c = cnt.incrementAndGet();
        if (c == numBatches * wqms) {
            testComplete();
        }
    });
    vertx.runOnContext(v -> {
        sendBatch(prod, wqms, numBatches, 0);
    });
    await(10, TimeUnit.SECONDS);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DeliveryOptions(io.vertx.core.eventbus.DeliveryOptions) Test(org.junit.Test)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7986 Test (org.junit.Test)3775 CountDownLatch (java.util.concurrent.CountDownLatch)1072 ArrayList (java.util.ArrayList)1018 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)849 List (java.util.List)740 IOException (java.io.IOException)719 AtomicReference (java.util.concurrent.atomic.AtomicReference)574 HashMap (java.util.HashMap)499 Map (java.util.Map)460 Test (org.testng.annotations.Test)419 File (java.io.File)337 ExecutorService (java.util.concurrent.ExecutorService)337 Test (org.junit.jupiter.api.Test)334 AtomicLong (java.util.concurrent.atomic.AtomicLong)329 TimeUnit (java.util.concurrent.TimeUnit)323 HashSet (java.util.HashSet)315 Arrays (java.util.Arrays)308 Set (java.util.Set)284 Collections (java.util.Collections)266