forked from infinispan/infinispan
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5155d24
commit 7e98516
Showing
126 changed files
with
11,300 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...ension/src/test/java/org/infinispan/cdi/test/DefaultTestEmbeddedCacheManagerProducer.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,46 @@ | ||
package org.infinispan.cdi.test; | ||
|
||
import org.infinispan.cdi.OverrideDefault; | ||
import org.infinispan.configuration.cache.Configuration; | ||
import org.infinispan.configuration.cache.ConfigurationBuilder; | ||
import org.infinispan.manager.EmbeddedCacheManager; | ||
import org.infinispan.test.TestingUtil; | ||
import org.infinispan.test.fwk.TestCacheManagerFactory; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Disposes; | ||
import javax.enterprise.inject.Instance; | ||
import javax.enterprise.inject.Produces; | ||
|
||
/** | ||
* <p>The alternative default {@link EmbeddedCacheManager} producer for the test environment.</p> | ||
* | ||
* @author Galder Zamarreño | ||
*/ | ||
public class DefaultTestEmbeddedCacheManagerProducer { | ||
|
||
/** | ||
* Produces the default embedded cache manager. | ||
* | ||
* @param providedDefaultEmbeddedCacheManager the provided default embedded cache manager. | ||
* @param defaultConfiguration the default configuration produced by the {@link DefaultTestEmbeddedCacheManagerProducer}. | ||
* @return the default embedded cache manager used by the application. | ||
*/ | ||
@Produces | ||
@ApplicationScoped | ||
public EmbeddedCacheManager getDefaultEmbeddedCacheManager(@OverrideDefault Instance<EmbeddedCacheManager> providedDefaultEmbeddedCacheManager, Configuration defaultConfiguration) { | ||
ConfigurationBuilder builder = new ConfigurationBuilder(); | ||
builder.read(defaultConfiguration); | ||
return TestCacheManagerFactory.createCacheManager(builder); | ||
} | ||
|
||
/** | ||
* Stops the default embedded cache manager when the corresponding instance is released. | ||
* | ||
* @param defaultEmbeddedCacheManager the default embedded cache manager. | ||
*/ | ||
private void stopCacheManager(@Disposes EmbeddedCacheManager defaultEmbeddedCacheManager) { | ||
TestingUtil.killCacheManagers(defaultEmbeddedCacheManager); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
cdi/extension/src/test/java/org/infinispan/cdi/test/ServiceLoaderTest.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,26 @@ | ||
package org.infinispan.cdi.test; | ||
|
||
import java.util.ServiceLoader; | ||
|
||
import javax.enterprise.inject.spi.Extension; | ||
|
||
import org.infinispan.cdi.InfinispanExtension; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.AssertJUnit.*; | ||
|
||
@Test(groups="functional", testName="cdi.test.ServiceLoaderTest") | ||
public class ServiceLoaderTest { | ||
|
||
public void testServiceLoaderExtension() { | ||
ServiceLoader<Extension> extensions = ServiceLoader.load(Extension.class); | ||
|
||
for(Extension extension : extensions) { | ||
if (extension instanceof InfinispanExtension) | ||
return; | ||
} | ||
fail("Could not load Infinispan CDI Extension"); | ||
} | ||
|
||
|
||
} |
56 changes: 56 additions & 0 deletions
56
cdi/extension/src/test/java/org/infinispan/cdi/test/cache/embedded/DefaultCacheTest.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,56 @@ | ||
package org.infinispan.cdi.test.cache.embedded; | ||
|
||
import org.infinispan.AdvancedCache; | ||
import org.infinispan.Cache; | ||
import org.infinispan.cdi.test.DefaultTestEmbeddedCacheManagerProducer; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.testng.Arquillian; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.testng.annotations.Test; | ||
|
||
import javax.inject.Inject; | ||
|
||
import static org.infinispan.cdi.test.testutil.Deployments.baseDeployment; | ||
import static org.infinispan.commons.api.BasicCacheContainer.DEFAULT_CACHE_NAME; | ||
import static org.testng.Assert.assertEquals; | ||
|
||
/** | ||
* Tests that the default cache is available and can be injected with no configuration. | ||
* | ||
* @author Pete Muir | ||
* @author Kevin Pollet <[email protected]> (C) 2011 SERLI | ||
*/ | ||
@Test(groups = "functional", testName = "cdi.test.cache.embedded.DefaultCacheTest") | ||
public class DefaultCacheTest extends Arquillian { | ||
|
||
@Deployment | ||
public static Archive<?> deployment() { | ||
return baseDeployment() | ||
.addClass(DefaultCacheTest.class) | ||
.addClass(DefaultTestEmbeddedCacheManagerProducer.class); | ||
} | ||
|
||
@Inject | ||
private Cache<String, String> cache; | ||
|
||
@Inject | ||
private AdvancedCache<String, String> advancedCache; | ||
|
||
public void testDefaultCache() { | ||
// Simple test to make sure the default cache works | ||
cache.put("pete", "British"); | ||
cache.put("manik", "Sri Lankan"); | ||
assertEquals(cache.get("pete"), "British"); | ||
assertEquals(cache.get("manik"), "Sri Lankan"); | ||
assertEquals(cache.getName(), DEFAULT_CACHE_NAME); | ||
/* | ||
* Check that the advanced cache contains the same data as the simple | ||
* cache. As we can inject either Cache or AdvancedCache, this is double | ||
* checking that they both refer to the same underlying impl and Seam | ||
* Clouds isn't returning the wrong thing. | ||
*/ | ||
assertEquals(advancedCache.get("pete"), "British"); | ||
assertEquals(advancedCache.get("manik"), "Sri Lankan"); | ||
assertEquals(advancedCache.getName(), DEFAULT_CACHE_NAME); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
cdi/extension/src/test/java/org/infinispan/cdi/test/cache/embedded/configured/Config.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,42 @@ | ||
package org.infinispan.cdi.test.cache.embedded.configured; | ||
|
||
import org.infinispan.cdi.ConfigureCache; | ||
import org.infinispan.configuration.cache.Configuration; | ||
import org.infinispan.configuration.cache.ConfigurationBuilder; | ||
|
||
import javax.enterprise.inject.Produces; | ||
|
||
/** | ||
* @author Kevin Pollet <[email protected]> (C) 2011 SERLI | ||
*/ | ||
public class Config { | ||
/** | ||
* <p>Configures a "tiny" cache (with a very low number of entries), and associates it with the qualifier {@link | ||
* Tiny}.</p> | ||
* | ||
* <p>This will use the default cache container.</p> | ||
*/ | ||
@Tiny | ||
@ConfigureCache("tiny") | ||
@Produces | ||
public Configuration tinyConfiguration() { | ||
return new ConfigurationBuilder() | ||
.eviction().maxEntries(1) | ||
.build(); | ||
} | ||
|
||
/** | ||
* <p>Configures a "small" cache (with a pretty low number of entries), and associates it with the qualifier {@link | ||
* Small}.</p> | ||
* | ||
* <p>This will use the default cache container.</p> | ||
*/ | ||
@Small | ||
@ConfigureCache("small") | ||
@Produces | ||
public Configuration smallConfiguration() { | ||
return new ConfigurationBuilder() | ||
.eviction().maxEntries(10) | ||
.build(); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
.../src/test/java/org/infinispan/cdi/test/cache/embedded/configured/ConfiguredCacheTest.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,49 @@ | ||
package org.infinispan.cdi.test.cache.embedded.configured; | ||
|
||
import org.infinispan.AdvancedCache; | ||
import org.infinispan.cdi.test.DefaultTestEmbeddedCacheManagerProducer; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.testng.Arquillian; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.testng.annotations.Test; | ||
|
||
import javax.inject.Inject; | ||
|
||
import static org.infinispan.cdi.test.testutil.Deployments.baseDeployment; | ||
import static org.testng.Assert.assertEquals; | ||
|
||
/** | ||
* Tests that the simple form of configuration works. | ||
* | ||
* @author Pete Muir | ||
* @author Kevin Pollet <[email protected]> (C) 2011 SERLI | ||
* @see Config | ||
*/ | ||
@Test(groups = "functional", testName = "cdi.test.cache.embedded.configured.ConfiguredCacheTest") | ||
public class ConfiguredCacheTest extends Arquillian { | ||
|
||
@Deployment | ||
public static Archive<?> deployment() { | ||
return baseDeployment() | ||
.addPackage(ConfiguredCacheTest.class.getPackage()) | ||
.addClass(DefaultTestEmbeddedCacheManagerProducer.class); | ||
} | ||
|
||
@Inject | ||
@Tiny | ||
private AdvancedCache<?, ?> tinyCache; | ||
|
||
@Inject | ||
@Small | ||
private AdvancedCache<?, ?> smallCache; | ||
|
||
public void testTinyCache() { | ||
// Check that we have the correctly configured cache | ||
assertEquals(tinyCache.getCacheConfiguration().eviction().maxEntries(), 1); | ||
} | ||
|
||
public void testSmallCache() { | ||
// Check that we have the correctly configured cache | ||
assertEquals(smallCache.getCacheConfiguration().eviction().maxEntries(), 10); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
cdi/extension/src/test/java/org/infinispan/cdi/test/cache/embedded/configured/Small.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,23 @@ | ||
package org.infinispan.cdi.test.cache.embedded.configured; | ||
|
||
import javax.inject.Qualifier; | ||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
/** | ||
* @author Kevin Pollet <[email protected]> (C) 2011 SERLI | ||
*/ | ||
@Qualifier | ||
@Target({TYPE, METHOD, PARAMETER, FIELD}) | ||
@Retention(RUNTIME) | ||
@Documented | ||
public @interface Small { | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
cdi/extension/src/test/java/org/infinispan/cdi/test/cache/embedded/configured/Tiny.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,23 @@ | ||
package org.infinispan.cdi.test.cache.embedded.configured; | ||
|
||
import javax.inject.Qualifier; | ||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
/** | ||
* @author Kevin Pollet <[email protected]> (C) 2011 SERLI | ||
*/ | ||
@Qualifier | ||
@Target({TYPE, METHOD, PARAMETER, FIELD}) | ||
@Retention(RUNTIME) | ||
@Documented | ||
public @interface Tiny { | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
cdi/extension/src/test/java/org/infinispan/cdi/test/cache/embedded/specific/Config.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,78 @@ | ||
package org.infinispan.cdi.test.cache.embedded.specific; | ||
|
||
import org.infinispan.cdi.ConfigureCache; | ||
import org.infinispan.configuration.cache.Configuration; | ||
import org.infinispan.configuration.cache.ConfigurationBuilder; | ||
import org.infinispan.eviction.EvictionStrategy; | ||
import org.infinispan.manager.EmbeddedCacheManager; | ||
import org.infinispan.test.TestingUtil; | ||
import org.infinispan.test.fwk.TestCacheManagerFactory; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Disposes; | ||
import javax.enterprise.inject.Produces; | ||
|
||
/** | ||
* @author Kevin Pollet <[email protected]> (C) 2011 SERLI | ||
*/ | ||
public class Config { | ||
|
||
/** | ||
* Associates the "large" cache with the qualifier {@link Large}. | ||
* | ||
* @param cacheManager the specific cache manager associated to this cache. This cache manager is used to get the | ||
* default cache configuration. | ||
*/ | ||
@Large | ||
@ConfigureCache("large") | ||
@Produces | ||
@SuppressWarnings("unused") | ||
public Configuration largeConfiguration(@Large EmbeddedCacheManager cacheManager) { | ||
return new ConfigurationBuilder() | ||
.read(cacheManager.getDefaultCacheConfiguration()) | ||
.eviction().maxEntries(2000) | ||
.build(); | ||
} | ||
|
||
/** | ||
* Associates the "small" cache with the qualifier {@link Small}. | ||
* | ||
* @param cacheManager the specific cache manager associated to this cache. This cache manager is used to get the | ||
* default cache configuration. | ||
*/ | ||
@Small | ||
@ConfigureCache("small") | ||
@Produces | ||
@SuppressWarnings("unused") | ||
public Configuration smallConfiguration(@Small EmbeddedCacheManager cacheManager) { | ||
return new ConfigurationBuilder() | ||
.read(cacheManager.getDefaultCacheConfiguration()) | ||
.eviction().maxEntries(20) | ||
.build(); | ||
} | ||
|
||
/** | ||
* Associates the "small" and "large" caches with this specific cache manager. | ||
*/ | ||
@Large | ||
@Small | ||
@Produces | ||
@ApplicationScoped | ||
@SuppressWarnings("unused") | ||
public EmbeddedCacheManager specificCacheManager() { | ||
ConfigurationBuilder builder = new ConfigurationBuilder(); | ||
builder.eviction().maxEntries(4000).strategy(EvictionStrategy.LIRS); | ||
return TestCacheManagerFactory.createCacheManager(builder); | ||
} | ||
|
||
/** | ||
* Stops cache manager. | ||
* | ||
* @param cacheManager to be stopped | ||
*/ | ||
@SuppressWarnings("unused") | ||
public void killCacheManager(@Disposes @Small @Large EmbeddedCacheManager cacheManager) { | ||
TestingUtil.killCacheManagers(cacheManager); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
cdi/extension/src/test/java/org/infinispan/cdi/test/cache/embedded/specific/Large.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,23 @@ | ||
package org.infinispan.cdi.test.cache.embedded.specific; | ||
|
||
import javax.inject.Qualifier; | ||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
/** | ||
* @author Kevin Pollet <[email protected]> (C) 2011 SERLI | ||
*/ | ||
@Qualifier | ||
@Target({TYPE, METHOD, PARAMETER, FIELD}) | ||
@Retention(RUNTIME) | ||
@Documented | ||
public @interface Large { | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
cdi/extension/src/test/java/org/infinispan/cdi/test/cache/embedded/specific/Small.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,23 @@ | ||
package org.infinispan.cdi.test.cache.embedded.specific; | ||
|
||
import javax.inject.Qualifier; | ||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
/** | ||
* @author Kevin Pollet <[email protected]> (C) 2011 SERLI | ||
*/ | ||
@Qualifier | ||
@Target({TYPE, METHOD, PARAMETER, FIELD}) | ||
@Retention(RUNTIME) | ||
@Documented | ||
public @interface Small { | ||
|
||
} |
Oops, something went wrong.