Skip to content

Commit

Permalink
Fixes tests and allows autohealing in fibers
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Venturi committed Jan 31, 2024
1 parent 4f77e34 commit e2c2bee
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/main/java/eu/lucaventuri/examples/ChoiceExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class ChoiceExample {
public static void main(String[] args) {
ActorUtils.runAsFiberScope(() -> System.out.println("Naked fiber 1!"), () -> System.out.println("Naked fiber 2!"), () -> System.out.println("Naked fiber 3!"));
// ActorUtils.runAsFiberScope(() -> System.out.println("Naked fiber 1!"), () -> System.out.println("Naked fiber 2!"), () -> System.out.println("Naked fiber 3!"));

ActorUtils.runAsFiber(() -> System.out.println("Naked fiber GS 1!"), () -> System.out.println("Naked fiber GS 2!"), () -> System.out.println("Naked fiber GS 3!"));

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/eu/lucaventuri/examples/HttpExampleMini.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ public class HttpExampleMini {
public static void main(String[] args) throws IOException {
int port = 18000;

System.out.println("Fibers V1 available: " + ActorUtils.areFibersV1Available());
System.out.println("Fibers V2 available: " + ActorUtils.areFibersV2Available());
System.out.println("Fibers available: " + ActorUtils.areFibersAvailable());
Stereotypes.def().embeddedHttpServer(port, new Stereotypes.HttpStringWorker("/", ex -> "Hello world from Fibry!"));
System.out.println("Listening on http://localhost:" + port);
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/eu/lucaventuri/fibry/ActorSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,6 @@ public NamedStateActorCreator<S> pollTimeout(int newPollTimeoutMs) {
}

public NamedStateActorCreator<S> autoHealing(AutoHealingSettings newAutoHealing) {
if (strategy == CreationStrategy.FIBER || (strategy == CreationStrategy.AUTO && ActorUtils.areFibersAvailable()))
throw new UnsupportedOperationException("AutoHealing for now is only supported on threads");
return new NamedStateActorCreator<S>(name, strategy, initialState, allowReuse, initializer, finalizer, closeStrategy, queueCapacity, pollTimeoutMs, newAutoHealing);
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/eu/lucaventuri/fibry/ActorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,7 @@ private static boolean isMethodHandler(Method method) {
}

public static ExecutorService newVirtualThreadsExecutor() {
try (ExecutorService virtualThreadPerTaskExecutor = Executors.newVirtualThreadPerTaskExecutor()) {
return virtualThreadPerTaskExecutor;
}
return Executors.newVirtualThreadPerTaskExecutor();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/eu/lucaventuri/fibry/Stereotypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public void embeddedHttpServer(int port, Function<HttpExchange, String> rootWork
public HttpServer embeddedHttpServer(int port, HttpStringWorker... workers) throws IOException {
//NamedStateActorCreator<Void> config = anonymous().initialState(null);
HttpServer server = HttpServer.create(new InetSocketAddress(port), defaultHttpBacklog.get());
server.setExecutor(AUTO.newExecutor());
server.setExecutor(FIBER.newExecutor());

for (HttpStringWorker worker : workers) {
server.createContext(worker.context, exchange -> {
Expand Down
19 changes: 5 additions & 14 deletions src/test/java/eu/lucaventuri/fibry/LoadTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,19 @@
public class LoadTests {
@Test
public void testHttp() throws IOException, URISyntaxException, InterruptedException {
boolean fibersAvailable = ActorUtils.areFibersAvailable();

System.out.println("Fibers: " + fibersAvailable);

var num = new AtomicInteger();
int port = 10001;
var url = new URL("http://localhost:" + port + "/test");
var uri = new URI("http://localhost:" + port + "/test");

Stereotypes.def().embeddedHttpServer(port, new Stereotypes.HttpStringWorker("/test", ex ->
""+num.incrementAndGet()));

final int numThreads;
final int numCalls;
final int numThreads = 250;
final int numCalls = 100;

if (fibersAvailable) {
numThreads = 250;
numCalls = 100;
} else {
numThreads = 100;
numCalls = 100;
}
System.out.println(uri);

//Thread.sleep(300_00);

CountDownLatch latch = new CountDownLatch(numThreads);
var client = HttpUtil.getHttpClient(10);
Expand Down
5 changes: 0 additions & 5 deletions src/test/java/eu/lucaventuri/fibry/TestAutoHealing.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ public void testMax() throws InterruptedException, ExecutionException {
Assert.assertTrue(end - partial >= 3000);
}

@Test(expected = UnsupportedOperationException.class)
public void testFailOnFibers() {
ActorSystem.anonymous().strategy(CreationStrategy.FIBER).autoHealing(new ActorSystem.AutoHealingSettings(1, 2, null, null)).newActor(SystemUtils::sleepEnsure);
}

@Test
public void testMaxRecovering() throws InterruptedException, ExecutionException {
HealRegistry.INSTANCE.setGracePeriod(10, TimeUnit.MILLISECONDS);
Expand Down

0 comments on commit e2c2bee

Please sign in to comment.