Skip to content

Commit

Permalink
feat: add configuration to set default threading model for verticles
Browse files Browse the repository at this point in the history
Also adding Java 21 to testing matrix, in order to add support for virtual threads.
  • Loading branch information
kristian committed Jan 12, 2024
1 parent ab2593b commit 16b3375
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ jobs:
persist-credentials: false
fetch-depth: 0

- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '17.0'
java-version: '21.0'
cache: 'gradle'

- name: Get new version
Expand Down Expand Up @@ -117,7 +117,7 @@ jobs:
uses: actions/setup-java@v2
with:
distribution: 'temurin'
java-version: '17.0'
java-version: '21.0'
cache: 'gradle'

- name: Tag release commit
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/voter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

strategy:
matrix:
java: ['11.0', '17.0']
java: ['11.0', '17.0', '21.0']
platform: [ubuntu-22.04] # macOS-latest, windows-latest

steps:
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ plugins {
// community plugins
id 'com.diffplug.spotless' version '6.23.3'
id 'net.ltgt.errorprone' version '3.1.0'
id 'com.github.spotbugs' version '5.2.4'
id 'com.github.spotbugs' version '6.0.6'
id 'org.ajoberstar.grgit' version '5.2.1'
id 'com.github.ksoichiro.console.reporter' version '0.6.3'
id 'se.bjurr.violations.violations-gradle-plugin' version '1.52.7'
id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'org.sonarqube' version '4.4.1.3373'
id 'team.yi.semantic-gitlog' version '0.5.17'
id 'team.yi.semantic-gitlog' version '0.6.5'
}

group = 'io.neonbee'
Expand Down Expand Up @@ -179,7 +179,7 @@ spotlessGeneratedExtension.removeUnusedImports()
spotlessGeneratedExtension.endWithNewline()
spotlessGeneratedExtension.setLineEndings(LineEnding.UNIX)
spotlessGeneratedExtension.importOrderFile("${rootDir}/gradle/spotless/neonbee.importorder")
spotlessGeneratedExtension.eclipse('4.17.0').configFile "${rootDir}/gradle/spotless/eclipse-formatter.xml"
spotlessGeneratedExtension.eclipse('4.17').configFile "${rootDir}/gradle/spotless/eclipse-formatter.xml"
spotlessGeneratedExtension.custom 'Lambda fix', { it.replace('} )', '})').replace('} ,', '},') }

def spotlessApplyGenerated = spotlessGeneratedExtension.createIndependentApplyTask('spotlessApplyGenerated')
Expand Down
2 changes: 1 addition & 1 deletion gradle/staticCodeCheck.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spotless {
endWithNewline()
lineEndings 'UNIX'
importOrderFile("${rootDir}/gradle/spotless/neonbee.importorder")
eclipse('4.17.0').configFile "${rootDir}/gradle/spotless/eclipse-formatter.xml"
eclipse('4.17').configFile "${rootDir}/gradle/spotless/eclipse-formatter.xml"
custom 'Lambda fix', { it.replace('} )', '})').replace('} ,', '},') }

targetExclude sourceSets.generated.java.srcDirs.collect { fileTree(it).files } // will be handled by an own spotlessApplyGenerated
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class NeonBeeConfigConverter {
static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, NeonBeeConfig obj) {
for (java.util.Map.Entry<String, Object> member : json) {
switch (member.getKey()) {
case "defaultThreadingModel":
if (member.getValue() instanceof String) {
obj.setDefaultThreadingModel(io.vertx.core.ThreadingModel.valueOf((String) member.getValue()));
}
break;
case "deploymentTimeout":
if (member.getValue() instanceof Number) {
obj.setDeploymentTimeout(((Number) member.getValue()).intValue());
Expand Down Expand Up @@ -111,6 +116,9 @@ static void toJson(NeonBeeConfig obj, JsonObject json) {
}

static void toJson(NeonBeeConfig obj, java.util.Map<String, Object> json) {
if (obj.getDefaultThreadingModel() != null) {
json.put("defaultThreadingModel", obj.getDefaultThreadingModel().name());
}
json.put("deploymentTimeout", obj.getDeploymentTimeout());
if (obj.getEventBusCodecs() != null) {
JsonObject map = new JsonObject();
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/io/neonbee/config/NeonBeeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.vertx.codegen.annotations.DataObject;
import io.vertx.codegen.annotations.Fluent;
import io.vertx.core.Future;
import io.vertx.core.ThreadingModel;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.core.metrics.MetricsOptions;
Expand Down Expand Up @@ -73,6 +74,8 @@ public class NeonBeeConfig {

private Integer verticleDeploymentTimeout;

private ThreadingModel defaultThreadingModel;

private Map<String, String> eventBusCodecs = Map.of();

private String trackingDataHandlingStrategy = DEFAULT_TRACKING_DATA_HANDLING_STRATEGY;
Expand Down Expand Up @@ -360,6 +363,16 @@ public NeonBeeConfig setVerticleDeploymentTimeout(Integer verticleDeploymentTime
return this;
}

public ThreadingModel getDefaultThreadingModel() {
return defaultThreadingModel;
}

@Fluent
public NeonBeeConfig setDefaultThreadingModel(ThreadingModel threadingModel) {
this.defaultThreadingModel = threadingModel;
return this;
}

/**
* Gets a list of default codecs to register on the event bus.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,11 @@ static Future<DeploymentOptions> readVerticleConfig(Vertx vertx, String classNam
: config; // if there is no default config, or what we read was the default config return it
}).onFailure(throwable -> {
LOGGER.warn("Could not read deployment options for deployable {}", className, throwable);
}).onSuccess(config -> {
if (!config.containsKey("threadingModel")) {
config.put("threadingModel", NeonBee.get(vertx).getConfig()
.getDefaultThreadingModel().toString());
}
}).map(DeploymentOptions::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.neonbee.internal.scanner.ClassPathScanner;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Future;
import io.vertx.core.ThreadingModel;
import io.vertx.core.Verticle;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
Expand Down Expand Up @@ -206,6 +207,24 @@ void testReadVerticleConfigFailure() throws IOException {
.isEqualTo("test");
}

@Test
@DisplayName("test read verticle config threading model")
void testReadVerticleConfigThreadingModel() throws IOException {
NeonBee neonBeeMock = newNeonBeeMockForDeployment(
new NeonBeeOptions.Mutable().setWorkingDirectory(Path.of("")));
Vertx vertxMock = neonBeeMock.getVertx();
FileSystem fileSystemMock = vertxMock.fileSystem();

when(fileSystemMock.readFile(any()))
.thenReturn(failedFuture(new FileSystemException(new NoSuchFileException("file"))));
when(fileSystemMock.readFile(endsWith(".yml")))
.thenReturn(succeededFuture(Buffer.buffer("---\nha: true\nthreadingModel: WORKER")));

JsonObject defaultObject = new JsonObject().put("threadingModel", "EVENT_LOOP");
assertThat(DeployableVerticle.readVerticleConfig(vertxMock, "test", defaultObject).result().toJson())
.isEqualTo(new DeploymentOptions().setThreadingModel(ThreadingModel.WORKER).toJson());
}

@Test
@DisplayName("test scan class path")
@SuppressWarnings("rawtypes")
Expand Down

0 comments on commit 16b3375

Please sign in to comment.