-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The improvements mainly consist of running each individual call on a separate duplicated context, which better simulates what happens in practice (at least in Quarkus). Further, a new test for timeouts with Vert.x was added.
- Loading branch information
Showing
15 changed files
with
469 additions
and
104 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
testsuite/integration/src/test/java/io/smallrye/faulttolerance/vertx/ContextDescription.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.smallrye.faulttolerance.vertx; | ||
|
||
import java.util.Locale; | ||
import java.util.Objects; | ||
|
||
public final class ContextDescription { | ||
public final ExecutionStyle executionStyle; | ||
public final String contextClass; | ||
public final String uuid; | ||
public final String contextHash; | ||
|
||
ContextDescription(ExecutionStyle executionStyle, String contextClass, String uuid, String contextHash) { | ||
this.executionStyle = executionStyle; | ||
this.contextClass = contextClass; | ||
this.contextHash = contextHash; | ||
this.uuid = uuid; | ||
} | ||
|
||
public boolean isDuplicatedContext() { | ||
return "DuplicatedContext".equals(contextClass); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (!(o instanceof ContextDescription)) { | ||
return false; | ||
} | ||
ContextDescription that = (ContextDescription) o; | ||
return Objects.equals(executionStyle, that.executionStyle) | ||
&& Objects.equals(contextClass, that.contextClass) | ||
&& Objects.equals(uuid, that.uuid) | ||
&& Objects.equals(contextHash, that.contextHash); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(executionStyle, contextClass, uuid, contextHash); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return executionStyle.toString().toLowerCase(Locale.ROOT) | ||
+ "|" + contextClass | ||
+ "|" + uuid | ||
+ "|" + contextHash; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
testsuite/integration/src/test/java/io/smallrye/faulttolerance/vertx/ExecutionStyle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.smallrye.faulttolerance.vertx; | ||
|
||
public enum ExecutionStyle { | ||
EVENT_LOOP, | ||
WORKER, | ||
UNKNOWN, | ||
} |
71 changes: 71 additions & 0 deletions
71
testsuite/integration/src/test/java/io/smallrye/faulttolerance/vertx/VertxContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.smallrye.faulttolerance.vertx; | ||
|
||
import java.util.UUID; | ||
|
||
import io.vertx.core.Context; | ||
import io.vertx.core.impl.ContextInternal; | ||
|
||
// assumes that verticles are not used and no context is created explicitly, | ||
// which means that all contexts are event loop contexts | ||
public class VertxContext { | ||
private final ContextInternal context; | ||
|
||
public static VertxContext current() { | ||
return new VertxContext(ContextInternal.current()); | ||
} | ||
|
||
private VertxContext(ContextInternal context) { | ||
this.context = context; | ||
} | ||
|
||
public VertxContext duplicate() { | ||
return new VertxContext(context.duplicate()); | ||
} | ||
|
||
public void execute(ExecutionStyle style, Runnable runnable) { | ||
switch (style) { | ||
case EVENT_LOOP: | ||
context.runOnContext(ignored -> { | ||
runnable.run(); | ||
}); | ||
break; | ||
case WORKER: | ||
context.executeBlocking(() -> { | ||
runnable.run(); | ||
return null; | ||
}); | ||
break; | ||
default: | ||
throw new UnsupportedOperationException("" + style); | ||
} | ||
} | ||
|
||
public void setTimer(long delayInMillis, Runnable runnable) { | ||
boolean moveToWorker = Context.isOnWorkerThread(); | ||
context.setTimer(delayInMillis, ignored -> { | ||
if (moveToWorker) { | ||
context.executeBlocking(() -> { | ||
runnable.run(); | ||
return null; | ||
}); | ||
} else { | ||
runnable.run(); | ||
} | ||
}); | ||
} | ||
|
||
public ContextDescription describe() { | ||
String uuid = context.getLocal("my-uuid"); | ||
if (uuid == null) { | ||
uuid = UUID.randomUUID().toString(); | ||
context.putLocal("my-uuid", uuid); | ||
} | ||
|
||
ExecutionStyle executionStyle = Context.isOnEventLoopThread() | ||
? ExecutionStyle.EVENT_LOOP | ||
: (Context.isOnWorkerThread() ? ExecutionStyle.WORKER : ExecutionStyle.UNKNOWN); | ||
|
||
return new ContextDescription(executionStyle, context.getClass().getSimpleName(), uuid, | ||
"" + System.identityHashCode(context)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.