Skip to content

Commit

Permalink
more cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhee17 committed Apr 26, 2023
1 parent 1c12c96 commit ddbdbc3
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 166 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import com.linecorp.armeria.common.annotation.Nullable;

import io.netty.util.concurrent.FastThreadLocalThread;

/**
* {@link ThreadFactory} that creates non event loop threads.
*/
Expand All @@ -33,6 +35,11 @@ final class NonEventLoopThreadFactory extends AbstractThreadFactory {

@Override
Thread newThread(@Nullable ThreadGroup threadGroup, Runnable r, String name) {
return new BlockingFastThreadLocalThread(threadGroup, r, name);
return new FastThreadLocalThread(threadGroup, r, name) {
@Override
public boolean permitBlockingCalls() {
return true;
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,23 @@

import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import com.linecorp.armeria.common.util.ThreadFactories;
import com.linecorp.armeria.testing.junit5.common.EventLoopGroupExtension;

import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
import io.netty.channel.DefaultEventLoopGroup;
import io.netty.channel.EventLoopGroup;

class EventLoopMetricsTest {

@RegisterExtension
static EventLoopGroupExtension eventLoopGroup =
new EventLoopGroupExtension(2, ThreadFactories.builder("block-me")
.eventLoop(false)
.build());

private class BlockMe extends CountDownLatch implements Runnable {

AtomicInteger run = new AtomicInteger();
Expand Down Expand Up @@ -61,7 +70,7 @@ void test() {

final BlockMe task = new BlockMe();

final EventLoopGroup workers = new DefaultEventLoopGroup(2);
final EventLoopGroup workers = eventLoopGroup.get();
// Block both executors
workers.submit(task);
workers.submit(task);
Expand Down Expand Up @@ -89,7 +98,5 @@ void test() {
MoreMeters.measureAll(registry))
.containsEntry("foo.event.loop.workers#value", 2.0)
.containsEntry("foo.event.loop.pending.tasks#value", 0.0));

workers.shutdownGracefully();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

import com.linecorp.armeria.common.stream.StreamMessage;
import com.linecorp.armeria.internal.testing.AnticipatedException;
import com.linecorp.armeria.internal.testing.BlockingUtils;
import com.linecorp.armeria.testing.junit5.common.EventLoopExtension;

import io.netty.util.concurrent.EventExecutor;
Expand Down Expand Up @@ -96,7 +97,7 @@ void raceBetweenSubscriptionAndAbort(StreamMessage<Integer> stream) {
public void onSubscribe(Subscription s) {
try {
// Wait for `abort()` to be called.
latch.await();
BlockingUtils.await(latch);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.linecorp.armeria.internal.testing;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Semaphore;

public final class BlockingUtils {
Expand All @@ -33,5 +34,9 @@ public static void acquireUninterruptibly(Semaphore semaphore) {
semaphore.acquireUninterruptibly();
}

public static void await(CountDownLatch countDownLatch) throws InterruptedException {
countDownLatch.await();
}

private BlockingUtils() {}
}

0 comments on commit ddbdbc3

Please sign in to comment.