Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Make sure all caches are reset for every test.
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosmunoz committed Sep 12, 2014
1 parent 3a3d8ee commit bf59ba3
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 12 deletions.
7 changes: 5 additions & 2 deletions zanata-war/src/test/java/org/zanata/RestTest.java
Expand Up @@ -32,10 +32,10 @@
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.ext.h2.H2DataTypeFactory;
import org.infinispan.manager.CacheContainer;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.resteasy.client.ClientRequest;
import org.jboss.resteasy.client.ProxyFactory;
import org.jboss.seam.util.Naming;
import org.junit.After;
import org.junit.Before;
Expand All @@ -46,7 +46,7 @@
import org.zanata.rest.ResourceRequestEnvironment;
import org.zanata.rest.client.ZanataProxyFactory;
import org.zanata.rest.dto.VersionInfo;
import org.zanata.rest.helper.RemoteTestSignaler;
import org.zanata.util.ServiceLocator;

/**
* Provides basic test utilities to test raw REST APIs and compatibility.
Expand Down Expand Up @@ -122,6 +122,9 @@ public void prepareDataBeforeTest() {
@RemoteAfter
public void cleanDataAfterTest() {
dbUnitProvider.cleanDataAfterTest();
ServiceLocator.instance()
.getJndiComponent("java:jboss/infinispan/container/hibernate",
CacheContainer.class).stop();
}

@Before
Expand Down
Expand Up @@ -43,7 +43,6 @@ public InfinispanTestCacheContainer() {

@Override
public void start() {
stop();
this.delegate =
new DefaultCacheManager(getDefaultGlobalConfiguration());
this.delegate.start();
Expand Down
Expand Up @@ -76,7 +76,7 @@ protected void prepareDBUnitOperations() {
DatabaseOperation.CLEAN_INSERT));

addAfterTestOperation(new DataSetOperation(
"org/zanata/test/model/HistoryTestData.dbunit.xml",
"org/zanata/test/model/ClearAllTables.dbunit.xml",
DatabaseOperation.DELETE_ALL));
}

Expand Down
Expand Up @@ -7,11 +7,11 @@

import org.infinispan.manager.CacheContainer;
import org.jboss.resteasy.client.ClientResponse;
import org.jboss.seam.security.management.JpaIdentityStore;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.zanata.cache.InfinispanTestCacheContainer;
Expand Down Expand Up @@ -58,6 +58,11 @@ protected void prepareResources() {
resources.add(translatedDocResourceService);
}

@AfterMethod
protected void cleanup() {
cacheContainer.stop();
}

@Test(dataProvider = "ResourceTestData")
public void testPutGetResourceWithExtension(Resource sr) {
log.debug("put resource:" + sr.toString());
Expand Down
Expand Up @@ -19,6 +19,7 @@
import org.mockito.MockitoAnnotations;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -176,6 +177,11 @@ public void createClient() {
createBaseURI(RESOURCE_PATH));
}

@AfterMethod
protected void cleanup() {
cacheContainer.stop();
}

@Test
public void fetchEmptyListOfResources() {
doGetandAssertThatResourceListContainsNItems(0);
Expand Down
Expand Up @@ -10,6 +10,7 @@
import org.mockito.MockitoAnnotations;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.zanata.cache.InfinispanTestCacheContainer;
Expand Down Expand Up @@ -77,6 +78,11 @@ protected void prepareResources() {
resources.add(translatedDocResourceService);
}

@AfterMethod
protected void cleanup() {
cacheContainer.stop();
}

@Test
public void testDeleteTranslation() {
Resource res = resourceTestFactory.getTextFlowTest();
Expand Down
Expand Up @@ -120,6 +120,11 @@ protected void beforeMethod() throws Exception {
AutowireTransaction.instance().rollback();
}

@AfterMethod
protected void cleanup() {
cacheContainer.stop();
}

/**
* Use this test to individually test copy trans scenarios.
*/
Expand Down
Expand Up @@ -35,6 +35,7 @@
import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.zanata.ZanataDbunitJpaTest;
Expand Down Expand Up @@ -136,6 +137,11 @@ protected void beforeMethod() throws Exception {
.autowire(CopyVersionServiceImpl.class);
}

@AfterMethod
protected void cleanup() {
cacheContainer.stop();
}

@Test
public void testCopyVersionNotExist() {
String projectSlug = "non-exists-project";
Expand Down
Expand Up @@ -81,6 +81,11 @@ public void beforeMethod() {
tsCache.create();
}

@AfterMethod
protected void cleanup() {
cacheContainer.stop();
}

public void testGetLastModifiedTextFlowTarget() throws Exception {
// Given:
Long documentId = new Long("100");
Expand Down
Expand Up @@ -31,6 +31,7 @@
import org.dbunit.operation.DatabaseOperation;
import org.hamcrest.Matchers;
import org.infinispan.manager.CacheContainer;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.zanata.ZanataDbunitJpaTest;
Expand Down Expand Up @@ -96,6 +97,11 @@ public void initializeSeam() {
versionGroupServiceImpl = seam.autowire(VersionGroupServiceImpl.class);
}

@AfterMethod
protected void cleanup() {
cacheContainer.stop();
}

@Test
public void getLocaleStatisticTest1() {
LocaleId localeId = LocaleId.DE;
Expand Down
Expand Up @@ -42,7 +42,7 @@ public void beforeMethod() {

@AfterMethod
public void afterMethod() {
cache.destroy();
cacheContainer.stop();
}

public void getStatisticTest() throws Exception {
Expand Down
Expand Up @@ -17,6 +17,7 @@
import org.infinispan.manager.CacheContainer;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.zanata.ZanataDbunitJpaTest;
Expand Down Expand Up @@ -101,13 +102,16 @@ public void setUp() throws Exception {
.useImpl(TextFlowSearchServiceImpl.class)
.useImpl(ValidationServiceImpl.class).allowCycles();

// @formatter:off
handler = seam.autowire(GetTransUnitListHandler.class);
// @formatter:on
handler = seam.autowire(GetTransUnitListHandler.class);

jaHLocale = getEm().find(HLocale.class, 3L);
}

@AfterMethod
protected void cleanup() {
cacheContainer.stop();
}

private void prepareActionAndMockLocaleService(GetTransUnitList action) {
action.setEditorClientId(new EditorClientId("sessionId", 1));
action.setWorkspaceId(TestFixture.workspaceId(localeId, "plurals",
Expand Down
4 changes: 3 additions & 1 deletion zanata-war/src/test/resources/arquillian/persistence.xml
Expand Up @@ -67,7 +67,9 @@
<properties>
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.cache.region.factory_class"
value="org.hibernate.testing.cache.CachingRegionFactory" />
value="org.hibernate.cache.infinispan.JndiInfinispanRegionFactory" />
<property name="hibernate.cache.infinispan.cachemanager" value="java:jboss/infinispan/container/hibernate" />
<property name="hibernate.cache.region_prefix" value="" />
<property name="hibernate.hbm2ddl.auto" value="create-drop" />

<property name="hibernate.connection.provider_class"
Expand Down
9 changes: 7 additions & 2 deletions zanata-war/src/test/resources/arquillian/standalone.xml
Expand Up @@ -174,7 +174,10 @@
</thread-pools>
</subsystem>
<subsystem xmlns="urn:jboss:domain:infinispan:1.3">
<!-- Hibernate Cache settings -->
<cache-container name="hibernate" default-cache="local-query"
start="EAGER"
jndi-name="java:jboss/infinispan/container/hibernate"
module="org.jboss.as.jpa.hibernate:4">
<local-cache name="entity">
<transaction mode="NON_XA" />
Expand All @@ -193,9 +196,11 @@
</cache-container>
<!--
Hibernate search infinispan settings
- Default In-memory settings
Default In-memory settings
-->
<cache-container name="hibernate-search" default-cache="indexes" jndi-name="java:jboss/infinispan/container/hibernate-search" start="EAGER" module="org.jboss.as.clustering.web.infinispan">
<cache-container name="hibernate-search" default-cache="indexes"
jndi-name="java:jboss/infinispan/container/hibernate-search" start="EAGER"
module="org.jboss.as.clustering.web.infinispan">
<local-cache name="LuceneIndexesMetadata" start="EAGER" batching="false"/>
<local-cache name="LuceneIndexesData" start="EAGER" batching="false"/>
<local-cache name="LuceneIndexesLocking" start="EAGER" batching="false"/>
Expand Down

0 comments on commit bf59ba3

Please sign in to comment.