Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISPN-3593 Disallow storing a Lucene index when storeAsBinary is enabled
- Loading branch information
Showing
3 changed files
with
82 additions
and
6 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
66 changes: 66 additions & 0 deletions
66
...-v3/src/test/java/org/infinispan/lucene/configuration/NotStoreAsBinaryValidationTest.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,66 @@ | ||
package org.infinispan.lucene.configuration; | ||
|
||
import org.infinispan.Cache; | ||
import org.infinispan.configuration.cache.ConfigurationBuilder; | ||
import org.infinispan.lucene.CacheTestSupport; | ||
import org.infinispan.lucene.directory.DirectoryBuilder; | ||
import org.infinispan.manager.EmbeddedCacheManager; | ||
import org.infinispan.test.AbstractInfinispanTest; | ||
import org.infinispan.test.TestingUtil; | ||
import org.infinispan.test.fwk.TestCacheManagerFactory; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* Verifies that the Lucene Directory correctly refuses to use a Cache with store as binary enabled. | ||
* | ||
* @author Pedro Ruivo | ||
* @since 6.0 | ||
*/ | ||
@Test(groups = "functional", testName = "lucene.configuration.NotStoreAsBinaryValidationTest") | ||
public class NotStoreAsBinaryValidationTest extends AbstractInfinispanTest { | ||
|
||
private static final String INDEX_NAME = "test-index"; | ||
private static final String CACHE_NAME = "test-cache"; | ||
private static final String ERROR_MESSAGE_EXP = "ISPN(\\d)*: Lucene Directory for index '" + INDEX_NAME + | ||
"' can not use Cache '" + CACHE_NAME + "': store as binary enabled on the Cache configuration!"; | ||
|
||
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = ERROR_MESSAGE_EXP) | ||
public void failOnStoreKeysAsBinary() { | ||
ConfigurationBuilder builder = new ConfigurationBuilder(); | ||
builder.storeAsBinary().enable().storeKeysAsBinary(true); | ||
failIfStoreAsBinaryEnabled(builder); | ||
} | ||
|
||
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = ERROR_MESSAGE_EXP) | ||
public void failOnStoreValuesAsBinary() { | ||
ConfigurationBuilder builder = new ConfigurationBuilder(); | ||
builder.storeAsBinary().enable().storeValuesAsBinary(true); | ||
failIfStoreAsBinaryEnabled(builder); | ||
} | ||
|
||
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = ERROR_MESSAGE_EXP) | ||
public void failOnStoreKeysAndValuesAsBinary() { | ||
ConfigurationBuilder builder = new ConfigurationBuilder(); | ||
builder.storeAsBinary().enable() | ||
.storeValuesAsBinary(true) | ||
.storeKeysAsBinary(true); | ||
failIfStoreAsBinaryEnabled(builder); | ||
} | ||
|
||
private void failIfStoreAsBinaryEnabled(ConfigurationBuilder configuration) { | ||
EmbeddedCacheManager cacheManager = null; | ||
try { | ||
ConfigurationBuilder cfg = CacheTestSupport.createLocalCacheConfiguration(); | ||
cfg.storeAsBinary().enable(); | ||
cacheManager = TestCacheManagerFactory.createCacheManager(configuration); | ||
Cache cache = cacheManager.getCache(CACHE_NAME); | ||
|
||
DirectoryBuilder.newDirectoryInstance(cache, cache, cache, INDEX_NAME).create(); | ||
} finally { | ||
if (cacheManager != null) { | ||
TestingUtil.killCacheManagers(cacheManager); | ||
} | ||
} | ||
} | ||
|
||
} |