use of java.util.concurrent.atomic.AtomicInteger in project jetty.project by eclipse.
the class HalfCloseTest method testCompleteClose.
@Test
public void testCompleteClose() throws Exception {
Server server = new Server();
ServerConnector connector = new ServerConnector(server, 1, 1);
connector.setPort(0);
connector.setIdleTimeout(5000);
final AtomicInteger opened = new AtomicInteger(0);
final CountDownLatch closed = new CountDownLatch(1);
connector.addBean(new Connection.Listener() {
@Override
public void onOpened(Connection connection) {
opened.incrementAndGet();
}
@Override
public void onClosed(Connection connection) {
closed.countDown();
}
});
server.addConnector(connector);
TestHandler handler = new TestHandler();
server.setHandler(handler);
server.start();
try (Socket client = new Socket("localhost", connector.getLocalPort())) {
client.getOutputStream().write("GET / HTTP/1.0\r\n\r\n".getBytes());
IO.toString(client.getInputStream());
assertEquals(1, handler.getHandled());
assertEquals(1, opened.get());
}
assertEquals(true, closed.await(1, TimeUnit.SECONDS));
}
use of java.util.concurrent.atomic.AtomicInteger in project jetty.project by eclipse.
the class HalfCloseTest method testAsyncClose.
@Test
public void testAsyncClose() throws Exception {
Server server = new Server();
ServerConnector connector = new ServerConnector(server, 1, 1);
connector.setPort(0);
connector.setIdleTimeout(5000);
final AtomicInteger opened = new AtomicInteger(0);
final CountDownLatch closed = new CountDownLatch(1);
connector.addBean(new Connection.Listener() {
@Override
public void onOpened(Connection connection) {
opened.incrementAndGet();
}
@Override
public void onClosed(Connection connection) {
closed.countDown();
}
});
server.addConnector(connector);
AsyncHandler handler = new AsyncHandler();
server.setHandler(handler);
server.start();
try (Socket client = new Socket("localhost", connector.getLocalPort())) {
client.getOutputStream().write("GET / HTTP/1.0\r\n\r\n".getBytes());
IO.toString(client.getInputStream());
assertEquals(1, handler.getHandled());
assertEquals(1, opened.get());
}
assertEquals(true, closed.await(1, TimeUnit.SECONDS));
}
use of java.util.concurrent.atomic.AtomicInteger in project jetty.project by eclipse.
the class SpringXmlConfigurationTest method testNewObject.
@Test
public void testNewObject() throws Exception {
final String newDefaultValue = "NEW DEFAULT";
TestConfiguration.VALUE = 71;
URL url = SpringXmlConfigurationTest.class.getClassLoader().getResource(_configure);
final AtomicInteger count = new AtomicInteger(0);
XmlConfiguration configuration = new XmlConfiguration(url) {
@Override
public void initializeDefaults(Object object) {
super.initializeDefaults(object);
if (object instanceof TestConfiguration) {
count.incrementAndGet();
((TestConfiguration) object).setTestString0(newDefaultValue);
((TestConfiguration) object).setTestString1("WILL BE OVERRIDDEN");
}
}
};
Map<String, String> properties = new HashMap<String, String>();
properties.put("test", "xxx");
TestConfiguration nested = new TestConfiguration();
nested.setTestString0("nested");
configuration.getIdMap().put("nested", nested);
configuration.getProperties().putAll(properties);
TestConfiguration tc = (TestConfiguration) configuration.configure();
assertEquals(3, count.get());
assertEquals(newDefaultValue, tc.getTestString0());
assertEquals(-1, tc.getTestInt0());
assertEquals("SetValue", tc.getTestString1());
assertEquals(1, tc.getTestInt1());
assertEquals(newDefaultValue, tc.getNested().getTestString0());
assertEquals("nested", tc.getNested().getTestString1());
assertEquals(newDefaultValue, tc.getNested().getNested().getTestString0());
assertEquals("deep", tc.getNested().getNested().getTestString1());
assertEquals("deep", ((TestConfiguration) configuration.getIdMap().get("nestedDeep")).getTestString1());
assertEquals(2, ((TestConfiguration) configuration.getIdMap().get("nestedDeep")).getTestInt2());
assertEquals("xxx", tc.getTestString2());
}
use of java.util.concurrent.atomic.AtomicInteger in project jetty.project by eclipse.
the class ServerWriteThread method run.
@Override
public void run() {
final AtomicInteger m = new AtomicInteger();
try {
while (m.get() < messageCount) {
conn.write(new TextFrame().setPayload(message));
m.incrementAndGet();
if (slowness > 0) {
TimeUnit.MILLISECONDS.sleep(slowness);
}
}
} catch (InterruptedException | IOException e) {
LOG.warn(e);
}
}
use of java.util.concurrent.atomic.AtomicInteger in project jetty.project by eclipse.
the class ClientWriteThread method run.
@Override
public void run() {
final AtomicInteger m = new AtomicInteger();
try {
LOG.debug("Writing {} messages to connection {}", messageCount);
LOG.debug("Artificial Slowness {} ms", slowness);
Future<Void> lastMessage = null;
RemoteEndpoint remote = session.getRemote();
while (m.get() < messageCount) {
lastMessage = remote.sendStringByFuture(message + "/" + m.get() + "/");
m.incrementAndGet();
if (slowness > 0) {
TimeUnit.MILLISECONDS.sleep(slowness);
}
}
if (remote.getBatchMode() == BatchMode.ON)
remote.flush();
// block on write of last message
if (lastMessage != null)
// block on write
lastMessage.get(2, TimeUnit.MINUTES);
} catch (Exception e) {
LOG.warn(e);
}
}
Aggregations