Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISPN-7714 Test full-text queries in server mode
- Loading branch information
Showing
7 changed files
with
262 additions
and
7 deletions.
There are no files selected for viewing
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
145 changes: 145 additions & 0 deletions
145
...gration/testsuite/src/test/java/org/infinispan/server/test/query/RemoteQueryStringIT.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,145 @@ | ||
package org.infinispan.server.test.query; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
import java.io.File; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import org.apache.lucene.analysis.core.LowerCaseFilterFactory; | ||
import org.apache.lucene.analysis.core.StopFilterFactory; | ||
import org.apache.lucene.analysis.standard.StandardFilterFactory; | ||
import org.apache.lucene.analysis.standard.StandardTokenizerFactory; | ||
import org.hibernate.search.cfg.SearchMapping; | ||
import org.infinispan.Cache; | ||
import org.infinispan.arquillian.core.InfinispanResource; | ||
import org.infinispan.arquillian.core.RemoteInfinispanServer; | ||
import org.infinispan.arquillian.core.RunningServer; | ||
import org.infinispan.arquillian.core.WithRunningServer; | ||
import org.infinispan.client.hotrod.RemoteCache; | ||
import org.infinispan.client.hotrod.RemoteCacheManager; | ||
import org.infinispan.client.hotrod.Search; | ||
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; | ||
import org.infinispan.client.hotrod.marshall.ProtoStreamMarshaller; | ||
import org.infinispan.commons.util.Util; | ||
import org.infinispan.protostream.sampledomain.Transaction; | ||
import org.infinispan.protostream.sampledomain.marshallers.MarshallerRegistration; | ||
import org.infinispan.query.dsl.Query; | ||
import org.infinispan.query.dsl.QueryFactory; | ||
import org.infinispan.query.remote.client.ProtobufMetadataManagerConstants; | ||
import org.infinispan.query.spi.ProgrammaticSearchMappingProvider; | ||
import org.infinispan.server.test.category.Queries; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.exporter.ZipExporter; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* Test for full-text remote queries over HotRod. A ProgrammaticSearchMappingProvider is used to define the analyzers. | ||
* | ||
* @author anistor@redhat.com | ||
* @since 9.2 | ||
*/ | ||
@RunWith(Arquillian.class) | ||
@Category(Queries.class) | ||
public class RemoteQueryStringIT { | ||
|
||
private static RemoteCacheManager remoteCacheManager; | ||
|
||
@InfinispanResource("query-programmatic-search-mapping-provider") | ||
RemoteInfinispanServer server1; | ||
|
||
@BeforeClass | ||
public static void before() throws Exception { | ||
JavaArchive programmaticSearchMappingProviderArchive = ShrinkWrap.create(JavaArchive.class) | ||
.addClass(TestAnalyzerProvider.class) | ||
.addClass(TestSearchMappingFactory.class) | ||
.addClass(TestSearchMappingFactory.MySearchableEntity.class) | ||
.add(new StringAsset("Dependencies: org.infinispan.query, org.hibernate.search.engine"), "META-INF/MANIFEST.MF") | ||
.addAsServiceProvider(ProgrammaticSearchMappingProvider.class, TestAnalyzerProvider.class); | ||
|
||
String serverDir = System.getProperty("server1.dist"); | ||
programmaticSearchMappingProviderArchive.as(ZipExporter.class) | ||
.exportTo(new File(serverDir, "/standalone/deployments/test-ProgrammaticSearchMappingProvider.jar"), true); | ||
} | ||
|
||
@AfterClass | ||
public static void release() { | ||
if (remoteCacheManager != null) { | ||
remoteCacheManager.stop(); | ||
} | ||
} | ||
|
||
@Test | ||
@WithRunningServer(@RunningServer(name = "query-programmatic-search-mapping-provider")) | ||
public void testFullTextTermRightOperandAnalyzed() throws Exception { | ||
ConfigurationBuilder clientBuilder = new ConfigurationBuilder(); | ||
clientBuilder.addServer() | ||
.host(server1.getHotrodEndpoint().getInetAddress().getHostName()) | ||
.port(server1.getHotrodEndpoint().getPort()) | ||
.marshaller(new ProtoStreamMarshaller()); | ||
remoteCacheManager = new RemoteCacheManager(clientBuilder.build()); | ||
|
||
//initialize server-side serialization context | ||
RemoteCache<String, String> metadataCache = remoteCacheManager.getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME); | ||
metadataCache.put("sample_bank_account/bank.proto", Util.read(getClass().getResourceAsStream("/sample_bank_account/bank.proto"))); | ||
assertFalse(metadataCache.containsKey(ProtobufMetadataManagerConstants.ERRORS_KEY_SUFFIX)); | ||
|
||
//initialize client-side serialization context | ||
MarshallerRegistration.registerMarshallers(ProtoStreamMarshaller.getSerializationContext(remoteCacheManager)); | ||
|
||
RemoteCache<Integer, Transaction> remoteCache = remoteCacheManager.getCache(); | ||
remoteCache.clear(); | ||
|
||
remoteCache.put(1, createTransaction1()); | ||
|
||
QueryFactory qf = Search.getQueryFactory(remoteCache); | ||
Query q = qf.create("from sample_bank_account.Transaction where longDescription:'RENT'"); | ||
|
||
List<Transaction> list = q.list(); | ||
assertNotNull(list); | ||
assertEquals(1, list.size()); | ||
assertEquals(Transaction.class, list.get(0).getClass()); | ||
assertTransaction1(list.get(0)); | ||
} | ||
|
||
private Transaction createTransaction1() { | ||
Transaction tx = new Transaction(); | ||
tx.setId(1); | ||
tx.setAccountId(777); | ||
tx.setAmount(500); | ||
tx.setDate(new Date(1)); | ||
tx.setDescription("February rent"); | ||
tx.setLongDescription("February rent"); | ||
return tx; | ||
} | ||
|
||
private void assertTransaction1(Transaction tx) { | ||
assertNotNull(tx); | ||
assertEquals(1, tx.getId()); | ||
assertEquals(777, tx.getAccountId()); | ||
assertEquals(500, tx.getAmount(), 0); | ||
assertEquals(new Date(1), tx.getDate()); | ||
assertNotNull("February rent", tx.getDescription()); | ||
assertNotNull("february rent", tx.getLongDescription()); | ||
} | ||
|
||
public static final class TestAnalyzerProvider implements ProgrammaticSearchMappingProvider { | ||
|
||
@Override | ||
public void defineMappings(Cache cache, SearchMapping searchMapping) { | ||
searchMapping.analyzerDef("standard", StandardTokenizerFactory.class) | ||
.filter(StandardFilterFactory.class) | ||
.filter(LowerCaseFilterFactory.class) | ||
.filter(StopFilterFactory.class); | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...on/testsuite/src/test/java/org/infinispan/server/test/query/TestSearchMappingFactory.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,41 @@ | ||
package org.infinispan.server.test.query; | ||
|
||
import org.hibernate.search.annotations.Factory; | ||
import org.hibernate.search.annotations.Field; | ||
import org.hibernate.search.annotations.Indexed; | ||
import org.hibernate.search.cfg.SearchMapping; | ||
|
||
/** | ||
* A factory for {@link SearchMapping}s for testing. | ||
* | ||
* @author anistor@redhat.com | ||
*/ | ||
public class TestSearchMappingFactory { | ||
|
||
public TestSearchMappingFactory() { | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
@Factory | ||
public SearchMapping buildSearchMapping() { | ||
SearchMapping searchMapping = new SearchMapping(); | ||
searchMapping.entity(MySearchableEntity.class); | ||
return searchMapping; | ||
} | ||
|
||
@Indexed | ||
public static class MySearchableEntity { | ||
|
||
@Field | ||
public int i; | ||
|
||
public MySearchableEntity(int i) { | ||
this.i = i; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "MySearchableEntity{i=" + i + '}'; | ||
} | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
...r/integration/testsuite/src/test/resources/config/infinispan/custom-compat-marshaller.xml
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
15 changes: 15 additions & 0 deletions
15
...suite/src/test/resources/config/infinispan/query-programmatic-search-mapping-provider.xml
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,15 @@ | ||
<subsystem xmlns="urn:infinispan:server:core:9.2"> | ||
<cache-container name="local" default-cache="default"> | ||
<modules> | ||
<module name="deployment.test-ProgrammaticSearchMappingProvider.jar"/> | ||
</modules> | ||
<local-cache name="default"> | ||
<indexing index="ALL"> | ||
<property name="default.directory_provider">local-heap</property> | ||
<!-- Demonstrate that Hibernate Search is able to load a model mapping from global classloader --> | ||
<property name="hibernate.search.model_mapping">org.infinispan.server.test.query.TestSearchMappingFactory</property> | ||
</indexing> | ||
</local-cache> | ||
<local-cache name="memcachedCache"/> | ||
</cache-container> | ||
</subsystem> |