Skip to content

Commit

Permalink
OGM-1353 Create method to enable counters for infinispan in TestHelper
Browse files Browse the repository at this point in the history
  Some tests require generated id or sequences, this way we can keep track
  which tests in core use it and the remove it once OGM-1376 (Counter for local caches)
  is resolved.
  • Loading branch information
DavideD committed Jan 25, 2018
1 parent 419389b commit 95c38cd
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 9 deletions.
Expand Up @@ -24,6 +24,7 @@
import org.hibernate.ogm.utils.InvokedOperationsLoggingDialect;
import org.hibernate.ogm.utils.OgmTestCase;
import org.hibernate.ogm.utils.TestForIssue;
import org.hibernate.ogm.utils.TestHelper;
import org.hibernate.stat.Statistics;
import org.junit.Test;

Expand Down Expand Up @@ -224,6 +225,7 @@ private boolean isMultigetDialect() {
@Override
protected void configure(Map<String, Object> cfg) {
cfg.put( OgmProperties.GRID_DIALECT, InvokedOperationsLoggingDialect.class );
TestHelper.enableCountersForInfinispan( cfg );
}

private InvokedOperationsLoggingDialect getOperationsLogger() {
Expand Down
Expand Up @@ -16,6 +16,8 @@
import org.hibernate.Session;
import org.hibernate.ogm.utils.GridDialectType;
import org.hibernate.ogm.utils.SkipByGridDialect;
import org.hibernate.ogm.utils.TestHelper;
import org.hibernate.ogm.utils.jpa.GetterPersistenceUnitInfo;
import org.hibernate.ogm.utils.jpa.OgmJpaTestCase;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.jpa.FullTextEntityManager;
Expand Down Expand Up @@ -87,6 +89,11 @@ public void testHibernateSearchNativeAPIUsage() throws Exception {
entityManager.close();
}

@Override
protected void configure(GetterPersistenceUnitInfo info) {
TestHelper.enableCountersForInfinispan( info.getProperties() );
}

@Override
public Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { Insurance.class };
Expand Down
Expand Up @@ -9,13 +9,15 @@
import static org.fest.assertions.Assertions.assertThat;

import java.util.List;
import java.util.Map;

import org.apache.lucene.search.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.ogm.utils.GridDialectType;
import org.hibernate.ogm.utils.OgmTestCase;
import org.hibernate.ogm.utils.SkipByGridDialect;
import org.hibernate.ogm.utils.TestHelper;
import org.hibernate.search.FullTextQuery;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
Expand Down Expand Up @@ -60,6 +62,11 @@ public void testHibernateSearchJPAAPIUsage() throws Exception {
fts.close();
}

@Override
protected void configure(Map<String, Object> cfg) {
TestHelper.enableCountersForInfinispan( cfg );
}

@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { Insurance.class };
Expand Down
Expand Up @@ -8,6 +8,8 @@

import javax.persistence.EntityManager;

import org.hibernate.ogm.utils.TestHelper;
import org.hibernate.ogm.utils.jpa.GetterPersistenceUnitInfo;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -60,6 +62,11 @@ public void testAutoIdentifierGenerator() throws Exception {
em.getTransaction().commit();
}

@Override
protected void configure(GetterPersistenceUnitInfo info) {
TestHelper.enableCountersForInfinispan( info.getProperties() );
}

@Override
public Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Expand Down
Expand Up @@ -8,9 +8,12 @@

import static org.fest.assertions.Assertions.assertThat;

import java.util.Map;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.ogm.utils.OgmTestCase;
import org.hibernate.ogm.utils.TestHelper;
import org.junit.Test;

/**
Expand Down Expand Up @@ -50,6 +53,11 @@ public void testAutoIdentifierGenerator() throws Exception {
session.close();
}

@Override
protected void configure(Map<String, Object> cfg) {
TestHelper.enableCountersForInfinispan( cfg );
}

@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { DistributedRevisionControl.class };
Expand Down
Expand Up @@ -13,7 +13,8 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import org.hibernate.ogm.utils.TestHelper;
import org.hibernate.ogm.utils.jpa.GetterPersistenceUnitInfo;
import org.hibernate.ogm.utils.jpa.OgmJpaTestCase;

import static org.fest.assertions.Assertions.assertThat;
Expand Down Expand Up @@ -110,6 +111,11 @@ public void testCompositeEmbeddedId() throws Exception {
em.getTransaction().commit();
}

@Override
protected void configure(GetterPersistenceUnitInfo info) {
TestHelper.enableCountersForInfinispan( info.getProperties() );
}

@Override
public Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Expand Down
Expand Up @@ -11,6 +11,8 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.ogm.utils.TestHelper;
import org.hibernate.ogm.utils.jpa.GetterPersistenceUnitInfo;
import org.hibernate.ogm.utils.jpa.OgmJpaTestCase;

import static org.fest.assertions.Assertions.assertThat;
Expand Down Expand Up @@ -85,6 +87,11 @@ public void testSequenceIdGenerationInJTA() throws Exception {
em.getTransaction().commit();
}

@Override
protected void configure(GetterPersistenceUnitInfo info) {
TestHelper.enableCountersForInfinispan( info.getProperties() );
}

@Override
public Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Expand Down
Expand Up @@ -22,8 +22,8 @@
import org.hibernate.ogm.id.impl.OgmSequenceGenerator;
import org.hibernate.ogm.model.key.spi.IdSourceKey;
import org.hibernate.ogm.model.key.spi.IdSourceKeyMetadata;
import org.hibernate.ogm.utils.GridDialectType;
import org.hibernate.ogm.utils.SkipByGridDialect;
import org.hibernate.ogm.utils.TestHelper;
import org.hibernate.ogm.utils.jpa.GetterPersistenceUnitInfo;
import org.junit.Test;

/**
Expand Down Expand Up @@ -62,7 +62,6 @@ public void testFirstValueIsInitialValue() {
}

@Test
@SkipByGridDialect(value = GridDialectType.INFINISPAN)
public void testIncrements() throws InterruptedException {
final IdSourceKey generatorKey = buildIdGeneratorKey( ThreadSafetyEntity.class, THREAD_SAFETY_SEQUENCE );
final NextValueRequest nextValueRequest = new NextValueRequest( generatorKey, THREAD_SAFETY_INCREMENT, THREAD_SAFETY_FIRST_VALUE );
Expand All @@ -87,6 +86,11 @@ public void testIncrements() throws InterruptedException {
}
}

@Override
protected void configure(GetterPersistenceUnitInfo info) {
TestHelper.enableCountersForInfinispan( info.getProperties() );
}

@Override
public Class<?>[] getAnnotatedClasses() {
return new Class<?>[]{ InitialValueEntity.class, ThreadSafetyEntity.class };
Expand Down
Expand Up @@ -11,7 +11,8 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import org.hibernate.ogm.utils.TestHelper;
import org.hibernate.ogm.utils.jpa.GetterPersistenceUnitInfo;
import org.hibernate.ogm.utils.jpa.OgmJpaTestCase;

import static org.fest.assertions.Assertions.assertThat;
Expand Down Expand Up @@ -78,6 +79,11 @@ public void testTableIdGeneratorUsingLong() throws Exception {
em.getTransaction().commit();
}

@Override
protected void configure(GetterPersistenceUnitInfo info) {
TestHelper.enableCountersForInfinispan( info.getProperties() );
}

@Override
public Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Expand Down
Expand Up @@ -16,6 +16,8 @@
import org.hibernate.ogm.dialect.spi.NextValueRequest;
import org.hibernate.ogm.jpa.impl.OgmEntityManagerFactory;
import org.hibernate.ogm.model.key.spi.IdSourceKey;
import org.hibernate.ogm.utils.TestHelper;
import org.hibernate.ogm.utils.jpa.GetterPersistenceUnitInfo;
import org.hibernate.ogm.utils.jpa.OgmJpaTestCase;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.junit.Before;
Expand Down Expand Up @@ -65,6 +67,11 @@ protected IdentifierGenerator generateKeyMetadata(Class<?> entityClass) {
return generator;
}

@Override
protected void configure(GetterPersistenceUnitInfo info) {
TestHelper.enableCountersForInfinispan( info.getProperties() );
}

protected static class IncrementJob implements Runnable {

private final GridDialect dialect;
Expand Down
Expand Up @@ -19,6 +19,7 @@
import org.hibernate.ogm.backendtck.massindex.model.IndexedLabel;
import org.hibernate.ogm.backendtck.massindex.model.IndexedNews;
import org.hibernate.ogm.utils.SkipByGridDialect;
import org.hibernate.ogm.utils.TestHelper;
import org.hibernate.ogm.utils.jpa.GetterPersistenceUnitInfo;
import org.hibernate.ogm.utils.jpa.OgmJpaTestCase;
import org.hibernate.search.jpa.FullTextEntityManager;
Expand Down Expand Up @@ -137,7 +138,6 @@ public Class<?>[] getAnnotatedClasses() {
protected void configure(GetterPersistenceUnitInfo info) {
super.configure( info );
info.getProperties().setProperty( "hibernate.search.default.directory_provider", "ram" );
// Infinispan requires to be set to distribution mode for this test to pass
info.getProperties().setProperty( "hibernate.ogm.infinispan.configuration_resourcename", "infinispan-dist.xml" );
TestHelper.enableCountersForInfinispan( info.getProperties() );
}
}
Expand Up @@ -23,6 +23,7 @@
import org.hibernate.ogm.backendtck.massindex.model.IndexedNews;
import org.hibernate.ogm.utils.OgmTestCase;
import org.hibernate.ogm.utils.SkipByGridDialect;
import org.hibernate.ogm.utils.TestHelper;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.hibernate.search.query.dsl.QueryBuilder;
Expand Down Expand Up @@ -128,7 +129,6 @@ protected Class<?>[] getAnnotatedClasses() {
@Override
protected void configure(Map<String, Object> settings) {
settings.put( "hibernate.search.default.directory_provider", "ram" );
// Infinispan requires to be set to distribution mode for this test to pass
settings.put( "hibernate.ogm.infinispan.configuration_resourcename", "infinispan-dist.xml" );
TestHelper.enableCountersForInfinispan( settings );
}
}
13 changes: 13 additions & 0 deletions core/src/test/java/org/hibernate/ogm/utils/TestHelper.java
Expand Up @@ -416,4 +416,17 @@ private static DatastoreProviderType findByAssignableType(String value) {
}
}

/**
* If a tests uses sequences or auto-generated id, it requires counters in Infinispan Embedded.
* At the moment counters only work in clustered mode. Once we have counters for local caches as well,
* we can remove this method.
*
* @see <a href="https://hibernate.atlassian.net/browse/OGM-1376">OGM-1376</a>
*/
@SuppressWarnings("unchecked")
public static void enableCountersForInfinispan(@SuppressWarnings("rawtypes") Map cfg) {
// Infinispan requires to be set to distribution mode for this test to pass
cfg.put( "hibernate.ogm.infinispan.configuration_resource_name", "infinispan-dist.xml" );
}

}
Expand Up @@ -18,6 +18,7 @@
import org.hibernate.ogm.model.impl.DefaultIdSourceKeyMetadata;
import org.hibernate.ogm.model.key.spi.RowKey;
import org.hibernate.ogm.utils.OgmTestCase;
import org.hibernate.ogm.utils.TestHelper;
import org.infinispan.Cache;
import org.junit.Test;

Expand Down Expand Up @@ -79,6 +80,11 @@ private InfinispanEmbeddedDatastoreProvider getProvider() {
.getService( DatastoreProvider.class );
}

@Override
protected void configure(Map<String, Object> cfg) {
TestHelper.enableCountersForInfinispan( cfg );
}

@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { Family.class, Plant.class };
Expand Down
Expand Up @@ -40,6 +40,7 @@ public void shouldUseCachePerTable() {

@Override
protected void configure(Map<String, Object> cfg) {
super.configure( cfg );
cfg.put( InfinispanProperties.CACHE_MAPPING, CacheMappingType.CACHE_PER_KIND );
}
}
Expand Up @@ -43,6 +43,7 @@ public void shouldUseCachePerTable() {

@Override
protected void configure(Map<String, Object> cfg) {
super.configure( cfg );
cfg.put( OgmProperties.OPTION_CONFIGURATOR, new OptionConfigurator() {

@Override
Expand Down

0 comments on commit 95c38cd

Please sign in to comment.