alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Hibernate example source code file (AbstractNonFunctionalTestCase.java)

This example Hibernate source code file (AbstractNonFunctionalTestCase.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Hibernate tags/keywords

abstractnonfunctionaltestcase, after, cachetestsupport, cachetestsupport, exception, exception, interrupted, interruptedexception, logger, object, prefer_ipv4stack, prefer_ipv4stack, string, string, util

The Hibernate AbstractNonFunctionalTestCase.java source code

/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * Copyright (c) 2007, Red Hat, Inc. and/or it's affiliates or third-party contributors as
 * indicated by the @author tags or express copyright attribution
 * statements applied by the authors.  All third-party contributions are
 * distributed under license by Red Hat, Inc. and/or it's affiliates.
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package org.hibernate.test.cache.infinispan;

import java.util.Set;

import org.infinispan.Cache;
import org.jboss.logging.Logger;

import org.hibernate.cache.spi.RegionFactory;
import org.hibernate.cache.infinispan.util.CacheHelper;

import org.junit.After;
import org.junit.Before;

import org.hibernate.test.cache.infinispan.util.CacheTestSupport;

/**
 * Base class for all non-functional tests of Infinispan integration.
 *
 * @author Galder Zamarreño
 * @since 3.5
 */
public abstract class AbstractNonFunctionalTestCase extends org.hibernate.testing.junit4.BaseUnitTestCase {
	private static final Logger log = Logger.getLogger( AbstractNonFunctionalTestCase.class );

	public static final String REGION_PREFIX = "test";

	private static final String PREFER_IPV4STACK = "java.net.preferIPv4Stack";
	private String preferIPv4Stack;

    private CacheTestSupport testSupport = new CacheTestSupport();

	@Before
    public void prepareCacheSupport() throws Exception {
		preferIPv4Stack = System.getProperty( PREFER_IPV4STACK );
		System.setProperty( PREFER_IPV4STACK, "true" );

        testSupport.setUp();
    }

    @After
    public void releaseCachSupport() throws Exception {
        testSupport.tearDown();

		if ( preferIPv4Stack == null ) {
			System.clearProperty( PREFER_IPV4STACK );
		}
		else {
			System.setProperty( PREFER_IPV4STACK, preferIPv4Stack );
		}
    }

    protected void registerCache(Cache cache) {
        testSupport.registerCache(cache);
    }

    protected void unregisterCache(Cache cache) {
        testSupport.unregisterCache(cache);
    }

    protected void registerFactory(RegionFactory factory) {
        testSupport.registerFactory(factory);
    }

    protected void unregisterFactory(RegionFactory factory) {
        testSupport.unregisterFactory(factory);
    }

    protected CacheTestSupport getCacheTestSupport() {
        return testSupport;
    }

    protected void sleep(long ms) {
        try {
            Thread.sleep(ms);
        }
        catch (InterruptedException e) {
            log.warn("Interrupted during sleep", e);
        }
    }

    protected void avoidConcurrentFlush() {
        testSupport.avoidConcurrentFlush();
    }

    protected int getValidKeyCount(Set keys) {
       int result = 0;
       for (Object key : keys) {
          if (!(CacheHelper.isEvictAllNotification(key))) {
             result++;
          }
       }
       return result;
   }

}

Other Hibernate examples (source code examples)

Here is a short list of links related to this Hibernate AbstractNonFunctionalTestCase.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.