Skip to content

Commit

Permalink
Merge pull request quarkusio#38642 from karesti/dev-services-improv-i…
Browse files Browse the repository at this point in the history
…nfinispan

Adds config file overload for devservices in Infinispan
  • Loading branch information
geoand authored Feb 7, 2024
2 parents 44b8b12 + d6867b6 commit 54b43f5
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 5 deletions.
25 changes: 25 additions & 0 deletions docs/src/main/asciidoc/infinispan-dev-services.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,31 @@ Dev Services for Infinispan relies on Docker to start the broker.
If your environment does not support Docker, you will need to start the broker manually, or connect to an already running broker.
You can configure the broker address using `quarkus.infinispan-client.hosts`.

== Providing configuration to the running server
Dev Services for Infinispan will spin up an Infinispan with the infinispan.xml file by default.
However, there are cases where is helpful to provide some extra configuration to the server.
This can be done by adding configuration files in xml, yaml or json to the resources classpath and
providing the following configuration:

[source,properties]
----
quarkus.infinispan-client.devservices.config-files=server-config-override.xml <1>
----
<1> server-config-override.xml is a file under the resources folder

[source,xml]
----
<infinispan> <1>
<cache-container>
<local-cache name="my-local-cache"> <2>
<encoding media-type="application/x-protostream" />
</local-cache>
</cache-container>
</infinispan>
----
<1> The content of server-config-override.xml file
<2> By providing a cache configuration, this cache will be present on the server container

== Cross Site Replication
If you want run the Infinispan Server container with Cross Site Replication configuration, you need to provide a site name.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.infinispan.commons.util.Version;
import org.infinispan.server.test.core.InfinispanContainer;
import org.jboss.logging.Logger;
import org.testcontainers.containers.BindMode;

import io.quarkus.deployment.Feature;
import io.quarkus.deployment.IsNormal;
Expand Down Expand Up @@ -272,10 +273,16 @@ public QuarkusInfinispanContainer(String clientName, InfinispanDevServicesConfig
}
withUser(DEFAULT_USERNAME);
withPassword(InfinispanDevServiceProcessor.DEFAULT_PASSWORD);
String command = "";
String command = "-c infinispan.xml";
if (config.site.isPresent()) {
command = "-c infinispan-xsite.xml -Dinfinispan.site.name=" + config.site.get();
}
command = command + config.configFiles.map(files -> files.stream().map(file -> {
String userConfigFile = "/user-config/" + file;
withClasspathResourceMapping(file, userConfigFile, BindMode.READ_ONLY);
return " -c " + userConfigFile;
}).collect(Collectors.joining())).orElse("");

if (config.mcastPort.isPresent()) {
command = command + " -Djgroups.mcast_port=" + config.mcastPort.getAsInt();
}
Expand All @@ -284,10 +291,10 @@ public QuarkusInfinispanContainer(String clientName, InfinispanDevServicesConfig
command = command + " -Dotel.exporter.otlp.endpoint=" + config.exporterOtlpEndpoint.get();
command = command + " -Dotel.service.name=infinispan-server-service -Dotel.metrics.exporter=none";
}
if (!command.isEmpty()) {
withCommand(command);
}

config.artifacts.ifPresent(a -> withArtifacts(a.toArray(new String[0])));

withCommand(command);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

package io.quarkus.infinispan.test;

import static org.assertj.core.api.Assertions.assertThat;

import jakarta.enterprise.inject.Default;

import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.counter.api.CounterManager;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.arc.Arc;
import io.quarkus.test.QuarkusUnitTest;

public class CreateADefaultRemoteCacheManagerWithEmptyConfTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withConfigurationResource("empty-application-infinispan-client.properties");

@Test
public void remoteCacheManagerDefaultBeansAccessible() {
assertThat(Arc.container().instance(RemoteCacheManager.class, Default.Literal.INSTANCE).get()).isNotNull();
assertThat(Arc.container().instance(CounterManager.class, Default.Literal.INSTANCE).get()).isNotNull();
assertThat(Arc.container().listAll(RemoteCacheManager.class).size()).isEqualTo(1);
assertThat(Arc.container().listAll(CounterManager.class).size()).isEqualTo(1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

package io.quarkus.infinispan.test;

import static org.assertj.core.api.Assertions.assertThat;

import jakarta.inject.Inject;

import org.infinispan.client.hotrod.RemoteCacheManager;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;

public class OverrideContainerConfigOnDevServicesTest {

@Inject
RemoteCacheManager cacheManager;

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.withApplicationRoot((jar) -> jar
.addAsResource("server-config-override.xml"))
.withConfigurationResource("dev-services-adds-server-config.properties");

@Test
public void remoteCacheManagerDefaultBeansAccessible() {
assertThat(cacheManager.getCacheNames()).contains("my-local-cache");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
quarkus.infinispan-client.devservices.enabled=true
quarkus.infinispan-client.devservices.config-files=server-config-override.xml

Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<infinispan>
<cache-container>
<metrics accurate-size="true"/>
<local-cache name="my-local-cache">
<encoding media-type="application/x-protostream" />
</local-cache>
</cache-container>
</infinispan>
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ public class InfinispanDevServicesConfig {
@ConfigItem
public Map<String, String> containerEnv;

/**
* Infinispan Server configuration chunks to be passed to the container.
*/
@ConfigItem
public Optional<List<String>> configFiles;

@Override
public boolean equals(Object o) {
if (this == o)
Expand Down

0 comments on commit 54b43f5

Please sign in to comment.