use of java.util.concurrent.ConcurrentSkipListSet in project hbase by apache.
the class TestProcedureSchedulerConcurrency method testConcurrentWaitWake.
private void testConcurrentWaitWake(final boolean useWakeBatch) throws Exception {
final int WAIT_THRESHOLD = 2500;
final int NPROCS = 20;
final int NRUNS = 500;
final ProcedureScheduler sched = procSched;
for (long i = 0; i < NPROCS; ++i) {
sched.addBack(new TestProcedureWithEvent(i));
}
final Thread[] threads = new Thread[4];
final AtomicInteger waitCount = new AtomicInteger(0);
final AtomicInteger wakeCount = new AtomicInteger(0);
final ConcurrentSkipListSet<TestProcedureWithEvent> waitQueue = new ConcurrentSkipListSet<>();
threads[0] = new Thread() {
@Override
public void run() {
long lastUpdate = 0;
while (true) {
final int oldWakeCount = wakeCount.get();
if (useWakeBatch) {
ProcedureEvent[] ev = new ProcedureEvent[waitQueue.size()];
for (int i = 0; i < ev.length; ++i) {
ev[i] = waitQueue.pollFirst().getEvent();
LOG.debug("WAKE BATCH " + ev[i] + " total=" + wakeCount.get());
}
sched.wakeEvents(ev.length, ev);
wakeCount.addAndGet(ev.length);
} else {
int size = waitQueue.size();
while (size-- > 0) {
ProcedureEvent ev = waitQueue.pollFirst().getEvent();
sched.wakeEvent(ev);
LOG.debug("WAKE " + ev + " total=" + wakeCount.get());
wakeCount.incrementAndGet();
}
}
if (wakeCount.get() != oldWakeCount) {
lastUpdate = System.currentTimeMillis();
} else if (wakeCount.get() >= NRUNS && (System.currentTimeMillis() - lastUpdate) > WAIT_THRESHOLD) {
break;
}
Threads.sleepWithoutInterrupt(25);
}
}
};
for (int i = 1; i < threads.length; ++i) {
threads[i] = new Thread() {
@Override
public void run() {
while (true) {
TestProcedureWithEvent proc = (TestProcedureWithEvent) sched.poll();
if (proc == null)
continue;
sched.suspendEvent(proc.getEvent());
waitQueue.add(proc);
sched.waitEvent(proc.getEvent(), proc);
LOG.debug("WAIT " + proc.getEvent());
if (waitCount.incrementAndGet() >= NRUNS) {
break;
}
}
}
};
}
for (int i = 0; i < threads.length; ++i) {
threads[i].start();
}
for (int i = 0; i < threads.length; ++i) {
threads[i].join();
}
sched.clear();
}
use of java.util.concurrent.ConcurrentSkipListSet in project mapdb by jankotek.
the class ConcurrentSkipListSubSetTest method set5.
/**
* Returns a new set of first 5 ints.
*/
private NavigableSet set5() {
ConcurrentSkipListSet q = new ConcurrentSkipListSet();
assertTrue(q.isEmpty());
q.add(one);
q.add(two);
q.add(three);
q.add(four);
q.add(five);
q.add(zero);
q.add(seven);
NavigableSet s = q.subSet(one, true, seven, false);
assertEquals(5, s.size());
return s;
}
use of java.util.concurrent.ConcurrentSkipListSet in project spring-framework by spring-projects.
the class OriginHandshakeInterceptorTests method originNoMatchWithNullHostileCollection.
@Test
public void originNoMatchWithNullHostileCollection() throws Exception {
Map<String, Object> attributes = new HashMap<>();
WebSocketHandler wsHandler = Mockito.mock(WebSocketHandler.class);
this.servletRequest.addHeader(HttpHeaders.ORIGIN, "http://mydomain4.com");
OriginHandshakeInterceptor interceptor = new OriginHandshakeInterceptor();
Set<String> allowedOrigins = new ConcurrentSkipListSet<>();
allowedOrigins.add("http://mydomain1.com");
interceptor.setAllowedOrigins(allowedOrigins);
assertFalse(interceptor.beforeHandshake(request, response, wsHandler, attributes));
assertEquals(servletResponse.getStatus(), HttpStatus.FORBIDDEN.value());
}
use of java.util.concurrent.ConcurrentSkipListSet in project cassandra by apache.
the class SkipListMemIndex method search.
public RangeIterator<Long, Token> search(Expression expression) {
ByteBuffer min = expression.lower == null ? null : expression.lower.value;
ByteBuffer max = expression.upper == null ? null : expression.upper.value;
SortedMap<ByteBuffer, ConcurrentSkipListSet<DecoratedKey>> search;
if (min == null && max == null) {
throw new IllegalArgumentException();
}
if (min != null && max != null) {
search = index.subMap(min, expression.lower.inclusive, max, expression.upper.inclusive);
} else if (min == null) {
search = index.headMap(max, expression.upper.inclusive);
} else {
search = index.tailMap(min, expression.lower.inclusive);
}
RangeUnionIterator.Builder<Long, Token> builder = RangeUnionIterator.builder();
search.values().stream().filter(keys -> !keys.isEmpty()).forEach(keys -> builder.add(new KeyRangeIterator(keys)));
return builder.build();
}
use of java.util.concurrent.ConcurrentSkipListSet in project titan by thinkaurelius.
the class TestByteBuffer method testByte.
private static long testByte() {
LongObjectMap<ConcurrentSkipListSet<ByteEntry>> tx = new LongObjectHashMap<ConcurrentSkipListSet<ByteEntry>>(NUM);
for (int i = 0; i < NUM; i++) {
tx.put(i, new ConcurrentSkipListSet<ByteEntry>());
}
for (int i = 0; i < NUM; i++) {
for (int j = 0; j < NUM; j++) {
if (i == j)
continue;
if (Math.random() < FRACTION) {
ByteBuffer key = ByteBuffer.allocate(16);
key.putLong(5).putLong(j).flip();
ByteBuffer value = ByteBuffer.allocate(4);
value.putInt(random.nextInt(ROUNDSIZE)).flip();
tx.get(i).add(new ByteEntry(key, value));
}
}
}
long time = System.currentTimeMillis();
long sum = 0;
for (int t = 0; t < TRIALS; t++) {
for (int i = 0; i < NUM; i++) {
for (Vertex v : (new ByteVertex(i, tx)).getNeighbors(0)) {
sum += v.getId();
}
}
}
time = System.currentTimeMillis() - time;
return time;
}
Aggregations