use of java.util.concurrent.atomic.AtomicLong in project jetty.project by eclipse.
the class HTTP2CServerTest method testHTTP_2_0_DirectWithoutH2C.
@Test
public void testHTTP_2_0_DirectWithoutH2C() throws Exception {
AtomicLong fills = new AtomicLong();
// Remove "h2c", leaving only "http/1.1".
connector.clearConnectionFactories();
HttpConnectionFactory connectionFactory = new HttpConnectionFactory() {
@Override
public Connection newConnection(Connector connector, EndPoint endPoint) {
HttpConnection connection = new HttpConnection(getHttpConfiguration(), connector, endPoint, getHttpCompliance(), isRecordHttpComplianceViolations()) {
@Override
public void onFillable() {
fills.incrementAndGet();
super.onFillable();
}
};
return configure(connection, connector, endPoint);
}
};
connector.addConnectionFactory(connectionFactory);
connector.setDefaultProtocol(connectionFactory.getProtocol());
// Now send a HTTP/2 direct request, which
// will have the PRI * HTTP/2.0 preface.
byteBufferPool = new MappedByteBufferPool();
generator = new Generator(byteBufferPool);
ByteBufferPool.Lease lease = new ByteBufferPool.Lease(byteBufferPool);
generator.control(lease, new PrefaceFrame());
try (Socket client = new Socket("localhost", connector.getLocalPort())) {
OutputStream output = client.getOutputStream();
for (ByteBuffer buffer : lease.getByteBuffers()) output.write(BufferUtil.toArray(buffer));
// We sent a HTTP/2 preface, but the server has no "h2c" connection
// factory so it does not know how to handle this request.
InputStream input = client.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
String responseLine = reader.readLine();
Assert.assertThat(responseLine, Matchers.containsString(" 426 "));
while (true) {
if (reader.read() < 0)
break;
}
}
// Make sure we did not spin.
Thread.sleep(1000);
Assert.assertThat(fills.get(), Matchers.lessThan(5L));
}
use of java.util.concurrent.atomic.AtomicLong in project jetty.project by eclipse.
the class SchedulerTest method testLongCancel.
@Test
public void testLongCancel() throws Exception {
final AtomicLong executed = new AtomicLong();
Scheduler.Task task = _scheduler.schedule(new Runnable() {
@Override
public void run() {
executed.set(System.currentTimeMillis());
}
}, 2000, TimeUnit.MILLISECONDS);
Thread.sleep(1600);
Assert.assertTrue(task.cancel());
Thread.sleep(1000);
Assert.assertEquals(0, executed.get());
}
use of java.util.concurrent.atomic.AtomicLong in project jetty.project by eclipse.
the class SchedulerTest method testExecution.
@Test
public void testExecution() throws Exception {
final AtomicLong executed = new AtomicLong();
long expected = System.currentTimeMillis() + 1000;
Scheduler.Task task = _scheduler.schedule(new Runnable() {
@Override
public void run() {
executed.set(System.currentTimeMillis());
}
}, 1000, TimeUnit.MILLISECONDS);
Thread.sleep(1500);
Assert.assertFalse(task.cancel());
Assert.assertThat(executed.get(), Matchers.greaterThanOrEqualTo(expected));
Assert.assertThat(expected - executed.get(), Matchers.lessThan(1000L));
}
use of java.util.concurrent.atomic.AtomicLong in project jetty.project by eclipse.
the class SchedulerTest method testTwoExecution.
@Test
public void testTwoExecution() throws Exception {
final AtomicLong executed = new AtomicLong();
long expected = System.currentTimeMillis() + 1000;
Scheduler.Task task = _scheduler.schedule(new Runnable() {
@Override
public void run() {
executed.set(System.currentTimeMillis());
}
}, 1000, TimeUnit.MILLISECONDS);
Thread.sleep(1500);
Assert.assertFalse(task.cancel());
Assert.assertThat(executed.get(), Matchers.greaterThanOrEqualTo(expected));
Assert.assertThat(expected - executed.get(), Matchers.lessThan(1000L));
final AtomicLong executed1 = new AtomicLong();
long expected1 = System.currentTimeMillis() + 1000;
Scheduler.Task task1 = _scheduler.schedule(new Runnable() {
@Override
public void run() {
executed1.set(System.currentTimeMillis());
}
}, 1000, TimeUnit.MILLISECONDS);
Thread.sleep(1500);
Assert.assertFalse(task1.cancel());
Assert.assertThat(executed1.get(), Matchers.greaterThanOrEqualTo(expected1));
Assert.assertThat(expected1 - executed1.get(), Matchers.lessThan(1000L));
}
use of java.util.concurrent.atomic.AtomicLong in project druid by druid-io.
the class KafkaLookupExtractorFactoryTest method testCacheKeyScramblesDifferentStarts.
@Test
public void testCacheKeyScramblesDifferentStarts() {
final int n = 1000;
final KafkaLookupExtractorFactory factory = new KafkaLookupExtractorFactory(cacheManager, TOPIC, DEFAULT_PROPERTIES);
factory.getMapRef().set(ImmutableMap.<String, String>of());
final AtomicLong events = factory.getDoubleEventCount();
final List<byte[]> byteArrays = new ArrayList<>(n);
for (int i = 0; i < n; ++i) {
final LookupExtractor extractor = factory.get();
final byte[] myKey = extractor.getCacheKey();
// Not terribly efficient.. but who cares
for (byte[] byteArray : byteArrays) {
Assert.assertFalse(Arrays.equals(byteArray, myKey));
}
byteArrays.add(myKey);
events.incrementAndGet();
}
Assert.assertEquals(n, byteArrays.size());
}
Aggregations