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);
}
}
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();
}
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();
}
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();
}
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);
}
Aggregations