Index: pom.xml
===================================================================
--- pom.xml	(revision 2171)
+++ pom.xml	(working copy)
@@ -34,6 +34,24 @@
          <type>test-jar</type>
          <scope>test</scope>
       </dependency>
+      <dependency>
+         <groupId>org.infinispan</groupId>
+         <artifactId>infinispan-cachestore-bdbje</artifactId>
+         <version>${project.version}</version>
+         <scope>test</scope>
+      </dependency>
+      <dependency>
+         <groupId>org.infinispan</groupId>
+         <artifactId>infinispan-cachestore-jdbm</artifactId>
+         <version>${project.version}</version>
+         <scope>test</scope>
+      </dependency>
+      <dependency>
+         <groupId>org.infinispan</groupId>
+         <artifactId>infinispan-cachestore-jdbc</artifactId>
+         <version>${project.version}</version>
+         <scope>test</scope>
+      </dependency>
    </dependencies>
    
    <build>
Index: src/test/java/org/infinispan/lucene/profiling/CacheStoreStressTest.java
===================================================================
--- src/test/java/org/infinispan/lucene/profiling/CacheStoreStressTest.java	(revision 0)
+++ src/test/java/org/infinispan/lucene/profiling/CacheStoreStressTest.java	(revision 0)
@@ -0,0 +1,150 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.lucene.profiling;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.infinispan.Cache;
+import org.infinispan.config.Configuration;
+import org.infinispan.loaders.CacheLoaderConfig;
+import org.infinispan.loaders.bdbje.BdbjeCacheStoreConfig;
+import org.infinispan.loaders.file.FileCacheStoreConfig;
+import org.infinispan.loaders.jdbc.binary.JdbcBinaryCacheStoreConfig;
+import org.infinispan.loaders.jdbm.JdbmCacheStoreConfig;
+import org.infinispan.lucene.CacheKey;
+import org.infinispan.lucene.CacheTestSupport;
+import org.infinispan.lucene.DirectoryIntegrityCheck;
+import org.infinispan.lucene.InfinispanDirectory;
+import org.infinispan.manager.EmbeddedCacheManager;
+import org.infinispan.test.TestingUtil;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.testng.annotations.Test;
+
+/**
+ * Testcase verifying that the index is usable under stress even when any type of cachestore is configured.
+ * See ISPN-575 Corruption in data when using a permanent store
+ * 
+ * @author Sanne Grinovero
+ * @author Davide Di Somma
+ * @since 4.1
+ */
+public class CacheStoreStressTest {
+
+   private static final String indexName = "tempIndexName";
+   private static final File cacheStoreDir = new File("InfinispanTest");
+
+   private Cache<CacheKey, Object> cache;
+   private EmbeddedCacheManager cacheFactory;
+
+   private void createClusteredCacheManager(CacheStoreType type) {
+      Configuration configuration = CacheTestSupport.createTestConfiguration();
+      CacheLoaderConfig cacheStoreConfig = type.getCacheLoaderConfiguration();
+      configuration.getCacheLoaderManagerConfig().addCacheLoaderConfig(cacheStoreConfig);
+      //Issues are verified even without disabling passivation, but it looks like they happen
+      //more frequently when disabling it. Might have been just luck.
+      configuration.getCacheLoaderManagerConfig().setPassivation(false);
+      cacheFactory = TestCacheManagerFactory.createClusteredCacheManager(configuration);
+      cacheFactory.start();
+      cache = cacheFactory.getCache();
+      cache.clear();
+   }
+
+   public void createStoringDirectory() {
+      cacheStoreDir.mkdirs();
+   }
+
+   public void afterTest() {
+      TestingUtil.killCaches(cache);
+      TestingUtil.killCacheManagers(cacheFactory);
+      TestingUtil.recursiveFileRemove(indexName);
+      TestingUtil.recursiveFileRemove(cacheStoreDir);
+   }
+
+   @Test
+   public void profileTestInfinispanDirectoryWithSomeCacheStores() throws Exception {
+      for (CacheStoreType storeType : CacheStoreType.values()) {
+         createStoringDirectory();
+         try {
+            runTestOn(storeType);
+         } finally {
+            afterTest();
+         }
+      }
+   }
+
+   private void runTestOn(CacheStoreType storeType) throws InterruptedException, IOException {
+      createClusteredCacheManager(storeType);
+      InfinispanDirectory dir = new InfinispanDirectory(cache, indexName);
+      PerformanceCompareStressTest.stressTestDirectory(dir, "InfinispanClustered-Store:"+storeType.name());
+      DirectoryIntegrityCheck.verifyDirectoryStructure(cache, indexName);
+   }
+   
+   private enum CacheStoreType {
+      FILE {
+         @Override
+         public CacheLoaderConfig getCacheLoaderConfiguration() {
+            FileCacheStoreConfig fileConfig = new FileCacheStoreConfig();
+            fileConfig.setLocation(cacheStoreDir.getAbsolutePath());
+            return fileConfig;
+         }
+      },
+      JDBM {
+         @Override
+         public CacheLoaderConfig getCacheLoaderConfiguration() {
+            JdbmCacheStoreConfig jbdmConfig = new JdbmCacheStoreConfig();
+            jbdmConfig.setLocation(cacheStoreDir.getAbsolutePath());
+            return jbdmConfig;
+         }
+      },
+      BDBJE {
+         @Override
+         public CacheLoaderConfig getCacheLoaderConfiguration() {
+            BdbjeCacheStoreConfig bdbjeConfig = new BdbjeCacheStoreConfig();
+            bdbjeConfig.setLocation(cacheStoreDir.getAbsolutePath());
+            return bdbjeConfig;
+         }
+      },
+      JDBC_BINARY {
+         @Override
+         public CacheLoaderConfig getCacheLoaderConfiguration() {
+            JdbcBinaryCacheStoreConfig jdbcBinaryConfig = new JdbcBinaryCacheStoreConfig();
+            jdbcBinaryConfig.setBucketTableNamePrefix("TEST_CACHESTORE");
+            jdbcBinaryConfig.setIdColumnName("ID_COLUMN");
+            jdbcBinaryConfig.setIdColumnType("VARCHAR(255)");
+            jdbcBinaryConfig.setDataColumnName("DATA_COLUMN");
+            jdbcBinaryConfig.setDataColumnType("BINARY");
+            jdbcBinaryConfig.setTimestampColumnName("TIMESTAMP_COLUMN");
+            jdbcBinaryConfig.setTimestampColumnType("BIGINT");
+            jdbcBinaryConfig.setConnectionFactoryClass("org.infinispan.loaders.jdbc.connectionfactory.PooledConnectionFactory");
+            jdbcBinaryConfig.setConnectionUrl("jdbc:h2:mem:infinispan_binary_based;DB_CLOSE_DELAY=-1");
+            jdbcBinaryConfig.setUserName("sa");
+            jdbcBinaryConfig.setDriverClass("org.h2.Driver");
+            jdbcBinaryConfig.setCreateTableOnStart(true);
+            jdbcBinaryConfig.setDropTableOnExit(true);
+            return jdbcBinaryConfig;
+         }
+      };
+      abstract CacheLoaderConfig getCacheLoaderConfiguration();
+   }
+
+}
