// Path: src/test/java/test/utils/repository/custom/MyTitleRepositoryFactoryBean.java
// public class MyTitleRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable>
//         extends HazelcastRepositoryFactoryBean<T, S, ID> {
//     @Resource
//     private HazelcastInstance hazelcastInstance;
// 
//     /*
//      * Creates a new {@link MyTitleRepositoryFactoryBean} for the given repository interface.
//      */
//     public MyTitleRepositoryFactoryBean(Class<? extends T> repositoryInterface) {
//         super(repositoryInterface);
//     }
// 
//     /* Create a specialised repository factory.
//      *
//      * (non-Javadoc)
//      * @see org.springframework.data.hazelcast.repository.support.HazelcastRepositoryFactoryBean#createRepositoryFactory(org
//      * .springframework.data.keyvalue.core.KeyValueOperations, java.lang.Class, java.lang.Class)
//      */
//     @Override
//     protected MyTitleRepositoryFactory createRepositoryFactory(KeyValueOperations operations,
//                                                                Class<? extends AbstractQueryCreator<?, ?>> queryCreator,
//                                                                Class<? extends RepositoryQuery> repositoryQueryType) {
// 
//         return new MyTitleRepositoryFactory(operations, queryCreator, hazelcastInstance);
//     }
// 
// }


import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Set;
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.config.Config;
import com.hazelcast.config.TcpIpConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.hazelcast.repository.config.EnableHazelcastRepositories;
import test.utils.repository.custom.MyTitleRepositoryFactoryBean;
     * </P>
     */
    @PreDestroy
    public void preDestroy() {
        boolean testInstanceWasRunning = false;

        Set<HazelcastInstance> hazelcastInstances = Hazelcast.getAllHazelcastInstances();
        if (hazelcastInstances.size() != 0) {
            for (HazelcastInstance hazelcastInstance : hazelcastInstances) {
                if (TestConstants.CLIENT_INSTANCE_NAME.equals(hazelcastInstance.getName())) {
                    testInstanceWasRunning = true;
                }
                LOG.debug("Closing '{}'", hazelcastInstance);
                hazelcastInstance.shutdown();
            }
        }
        ;

        if (testInstanceWasRunning) {
            LOG.error("'{}' was still running", TestConstants.CLIENT_INSTANCE_NAME);
        } else {
            LOG.debug("'{}' already closed by Spring", TestConstants.CLIENT_INSTANCE_NAME);
        }
    }

    /**
     * <P>The {@code @EnableHazelcastRepositories} annotation is not repeatable,
     * so use an inner class to scan a second package.
     * </P>
     */
// Path: src/test/java/test/utils/repository/custom/MyTitleRepositoryFactoryBean.java
// public class MyTitleRepositoryFactoryBean<T extends Repository<S, ID>, S, ID extends Serializable>
//         extends HazelcastRepositoryFactoryBean<T, S, ID> {
//     @Resource
//     private HazelcastInstance hazelcastInstance;
// 
//     /*
//      * Creates a new {@link MyTitleRepositoryFactoryBean} for the given repository interface.
//      */
//     public MyTitleRepositoryFactoryBean(Class<? extends T> repositoryInterface) {
//         super(repositoryInterface);
//     }
// 
//     /* Create a specialised repository factory.
//      *
//      * (non-Javadoc)
//      * @see org.springframework.data.hazelcast.repository.support.HazelcastRepositoryFactoryBean#createRepositoryFactory(org
//      * .springframework.data.keyvalue.core.KeyValueOperations, java.lang.Class, java.lang.Class)
//      */
//     @Override
//     protected MyTitleRepositoryFactory createRepositoryFactory(KeyValueOperations operations,
//                                                                Class<? extends AbstractQueryCreator<?, ?>> queryCreator,
//                                                                Class<? extends RepositoryQuery> repositoryQueryType) {
// 
//         return new MyTitleRepositoryFactory(operations, queryCreator, hazelcastInstance);
//     }
// 
// }


// Path: src/test/java/test/utils/InstanceHelper.java
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Set;
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.config.Config;
import com.hazelcast.config.TcpIpConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.data.hazelcast.repository.config.EnableHazelcastRepositories;
import test.utils.repository.custom.MyTitleRepositoryFactoryBean;

     * </P>
     */
    @PreDestroy
    public void preDestroy() {
        boolean testInstanceWasRunning = false;

        Set<HazelcastInstance> hazelcastInstances = Hazelcast.getAllHazelcastInstances();
        if (hazelcastInstances.size() != 0) {
            for (HazelcastInstance hazelcastInstance : hazelcastInstances) {
                if (TestConstants.CLIENT_INSTANCE_NAME.equals(hazelcastInstance.getName())) {
                    testInstanceWasRunning = true;
                }
                LOG.debug("Closing '{}'", hazelcastInstance);
                hazelcastInstance.shutdown();
            }
        }
        ;

        if (testInstanceWasRunning) {
            LOG.error("'{}' was still running", TestConstants.CLIENT_INSTANCE_NAME);
        } else {
            LOG.debug("'{}' already closed by Spring", TestConstants.CLIENT_INSTANCE_NAME);
        }
    }

    /**
     * <P>The {@code @EnableHazelcastRepositories} annotation is not repeatable,
     * so use an inner class to scan a second package.
     * </P>
     */
    @EnableHazelcastRepositories(basePackages = "test.utils.repository.custom", repositoryFactoryBeanClass = MyTitleRepositoryFactoryBean.class, hazelcastInstanceRef = TestConstants.CLIENT_INSTANCE_NAME)