Skip to content

Commit

Permalink
Merge pull request #26647 from gsmet/ispn-dev-services
Browse files Browse the repository at this point in the history
Use Dev Services for Infinispan Client IT and enforce Hibernate Search constraint in BOM
  • Loading branch information
gsmet authored Jul 20, 2022
2 parents ba968f8 + e647753 commit d3b6187
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 234 deletions.
2 changes: 0 additions & 2 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4858,7 +4858,6 @@
</exclusion>
</exclusions>
</dependency>
<!-- TODO current infinispan-client is using 6.0.8 and isn't breaking with the following constraints
<dependency>
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-engine</artifactId>
Expand All @@ -4874,7 +4873,6 @@
<artifactId>hibernate-search-util-common</artifactId>
<version>${hibernate-search.version}</version>
</dependency>
-->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand Down
79 changes: 39 additions & 40 deletions integration-tests/infinispan-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,6 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-server-hotrod</artifactId>
<scope>test</scope>
<exclusions>
<!-- fix dependency convergence with quarkus-junit5 -->
<exclusion>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
</exclusion>
<!-- jboss-transaction-api is banned and not required for the test -->
<exclusion>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- needed so server exposes query based caches -->
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-remote-query-server</artifactId>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-serialization-avro</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>commons-logging-jboss-logging</artifactId>
Expand All @@ -102,12 +69,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-server-hotrod</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-component-annotations</artifactId>
Expand Down Expand Up @@ -200,9 +161,47 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>


<profiles>
<!-- Note: the container is started via Dev Services -->
<profile>
<id>test-infinispan</id>
<activation>
<property>
<name>test-containers</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package io.quarkus.it.infinispan.client;

import java.math.BigDecimal;
import java.time.YearMonth;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;

import org.infinispan.client.hotrod.RemoteCache;
import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.client.hotrod.Search;
import org.infinispan.client.hotrod.annotation.ClientCacheEntryCreated;
import org.infinispan.client.hotrod.annotation.ClientCacheEntryModified;
import org.infinispan.client.hotrod.annotation.ClientCacheEntryRemoved;
import org.infinispan.client.hotrod.annotation.ClientListener;
import org.infinispan.client.hotrod.event.ClientCacheEntryCreatedEvent;
import org.infinispan.client.hotrod.event.ClientCacheEntryModifiedEvent;
import org.infinispan.client.hotrod.event.ClientCacheEntryRemovedEvent;
import org.infinispan.client.hotrod.logging.Log;
import org.infinispan.client.hotrod.logging.LogFactory;
import org.infinispan.commons.configuration.XMLStringConfiguration;
import org.infinispan.query.api.continuous.ContinuousQuery;
import org.infinispan.query.api.continuous.ContinuousQueryListener;
import org.infinispan.query.dsl.Query;
import org.infinispan.query.dsl.QueryFactory;

import io.quarkus.runtime.StartupEvent;

@ApplicationScoped
public class CacheSetup {

private static final Log log = LogFactory.getLog(CacheSetup.class);

public static final String DEFAULT_CACHE = "default";
public static final String MAGAZINE_CACHE = "magazine";

@Inject
RemoteCacheManager cacheManager;

private final Map<String, Book> matches = new ConcurrentHashMap<>();

private CountDownLatch waitUntilStarted = new CountDownLatch(1);

private static final String CACHE_CONFIG = "<distributed-cache name=\"%s\">"
+ " <encoding media-type=\"application/x-protostream\"/>"
+ "</distributed-cache>";

void onStart(@Observes StartupEvent ev) {
RemoteCache<String, Book> defaultCache = cacheManager.administration().getOrCreateCache(DEFAULT_CACHE,
new XMLStringConfiguration(String.format(CACHE_CONFIG, DEFAULT_CACHE)));
RemoteCache<String, Magazine> magazineCache = cacheManager.administration().getOrCreateCache(MAGAZINE_CACHE,
new XMLStringConfiguration(String.format(CACHE_CONFIG, MAGAZINE_CACHE)));

defaultCache.addClientListener(new EventPrintListener());

ContinuousQuery<String, Book> continuousQuery = Search.getContinuousQuery(defaultCache);

QueryFactory queryFactory = Search.getQueryFactory(defaultCache);
Query query = queryFactory.create("from book_sample.Book where publicationYear > 2011");

ContinuousQueryListener<String, Book> listener = new ContinuousQueryListener<String, Book>() {
@Override
public void resultJoining(String key, Book value) {
log.warn("Adding key: " + key + " for book: " + value);
matches.put(key, value);
}

@Override
public void resultLeaving(String key) {
log.warn("Removing key: " + key);
matches.remove(key);
}

@Override
public void resultUpdated(String key, Book value) {
log.warn("Entry updated: " + key);
}
};

continuousQuery.addContinuousQueryListener(query, listener);

log.info("Added continuous query listener");

defaultCache.put("book1", new Book("Game of Thrones", "Lots of people perish", 2010,
Collections.singleton(new Author("George", "Martin")), Type.FANTASY, new BigDecimal("23.99")));
defaultCache.put("book2", new Book("Game of Thrones Path 2", "They win?", 2023,
Collections.singleton(new Author("Son", "Martin")), Type.FANTASY, new BigDecimal("54.99")));

magazineCache.put("first-mad", new Magazine("MAD", YearMonth.of(1952, 10),
Collections.singletonList("Blob named Melvin")));
magazineCache.put("first-time", new Magazine("TIME", YearMonth.of(1923, 3),
Arrays.asList("First helicopter", "Change in divorce law", "Adam's Rib movie released",
"German Reparation Payments")));
magazineCache.put("popular-time", new Magazine("TIME", YearMonth.of(1997, 4),
Arrays.asList("Yep, I'm gay", "Backlash against HMOS", "False Hope on Breast Cancer?")));

waitUntilStarted.countDown();
}

public void ensureStarted() {
try {
if (!waitUntilStarted.await(10, TimeUnit.SECONDS)) {
throw new RuntimeException(new TimeoutException());
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

public Map<String, Book> getMatches() {
return matches;
}

@ClientListener
static class EventPrintListener {

@ClientCacheEntryCreated
public void handleCreatedEvent(ClientCacheEntryCreatedEvent e) {
log.warn("Someone has created an entry: " + e);
}

@ClientCacheEntryModified
public void handleModifiedEvent(ClientCacheEntryModifiedEvent e) {
log.warn("Someone has modified an entry: " + e);
}

@ClientCacheEntryRemoved
public void handleRemovedEvent(ClientCacheEntryRemovedEvent e) {
log.warn("Someone has removed an entry: " + e);
}
}
}
Loading

0 comments on commit d3b6187

Please sign in to comment.