[infinispan-commits] Infinispan SVN: r953 - in trunk/core/src: test/java/org/infinispan/config and 1 other directory.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Thu Oct 15 09:43:33 EDT 2009


Author: mircea.markus
Date: 2009-10-15 09:43:33 -0400 (Thu, 15 Oct 2009)
New Revision: 953

Added:
   trunk/core/src/test/java/org/infinispan/config/SampleConfigFilesCorrectnessTest.java
Modified:
   trunk/core/src/main/resources/config-samples/all.xml
Log:
[ISPN-196] - (create a unit test to verify the correctenss of supplied sample files) - done

Modified: trunk/core/src/main/resources/config-samples/all.xml
===================================================================
--- trunk/core/src/main/resources/config-samples/all.xml	2009-10-15 13:30:41 UTC (rev 952)
+++ trunk/core/src/main/resources/config-samples/all.xml	2009-10-15 13:43:33 UTC (rev 953)
@@ -42,13 +42,9 @@
          There is no added cost to defining a transport but not creating a cache that uses one, since the transport
          is created and initialized lazily.
       -->
-      <transport clusterName="infinispan-cluster" distributedSyncTimeout="50000" nodeName="Jalapeno">
+      <transport clusterName="infinispan-cluster" distributedSyncTimeout="50000" nodeName="Jalapeno"/>
          <!-- Note that the JGroups transport uses sensible defaults if no configuration property is defined. -->
-         <properties>
-         	<property name="configurationFile" value="udp.xml"/>
-         </properties>
          <!-- See the JGroupsTransport javadocs for more flags -->
-      </transport>
 
       <!-- Again, sensible defaults are used here if this is omitted.  -->
       <serialization marshallerClass="org.infinispan.marshall.VersionAwareMarshaller" version="1.0"/>
@@ -166,7 +162,7 @@
 
             <!-- See the documentation for more configuration examples and flags. -->
             <properties>
-               <property name="location" value="/tmp"/>
+               <property name="location" value="${java.io.tmpdir}"/>
             </properties>
             <singletonStore enabled="true" pushStateWhenCoordinator="true" pushStateTimeout="20000"/>
             <async enabled="true" mapLockTimeout="15000" threadPoolSize="5"/>

Added: trunk/core/src/test/java/org/infinispan/config/SampleConfigFilesCorrectnessTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/config/SampleConfigFilesCorrectnessTest.java	                        (rev 0)
+++ trunk/core/src/test/java/org/infinispan/config/SampleConfigFilesCorrectnessTest.java	2009-10-15 13:43:33 UTC (rev 953)
@@ -0,0 +1,137 @@
+package org.infinispan.config;
+
+import org.apache.log4j.AppenderSkeleton;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.spi.LoggingEvent;
+import org.infinispan.Cache;
+import org.infinispan.manager.DefaultCacheManager;
+import org.infinispan.test.TestingUtil;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.Arrays;
+
+/**
+ * Tests the correctness of the supplied configuration files.
+ *
+ * @author Mircea.Markus at jboss.com
+ */
+ at Test(groups = "functional", testName = "config.SampleConfigFilesCorrectnessTest")
+public class SampleConfigFilesCorrectnessTest {
+   public static final String CONFIG_ROOT = "src/main/resources/config-samples";
+
+   private InMemoryAppender appender;
+   private Level oldLevel;
+
+   @BeforeMethod
+   public void setUpTest() {
+      Logger log4jLogger = Logger.getRootLogger();
+      oldLevel = log4jLogger.getLevel();
+      log4jLogger.setLevel(Level.WARN);
+      appender = new InMemoryAppender();
+      log4jLogger.addAppender(appender);
+   }
+
+   @AfterMethod
+   public void tearDownTest() {
+      Logger log4jLogger = Logger.getRootLogger();
+      log4jLogger.setLevel(oldLevel);
+      log4jLogger.removeAppender(appender);
+      appender.close();
+   }
+
+
+   public void testConfigWarnings() throws Exception {
+      for (String aConfFile : getConfigFileNames()) {
+         DefaultCacheManager dcm = new DefaultCacheManager(getRootFolder() + "/" + aConfFile);
+         try {
+            Cache defaultCache = dcm.getCache();
+            assert !appender.isFoundUnknownWarning();
+            for (String cacheName : dcm.getCacheNames()) {
+               dcm.getCache(cacheName);
+               assert !appender.isFoundUnknownWarning();
+            }
+         } finally {
+            TestingUtil.killCacheManagers(dcm);
+         }
+      }
+   }
+
+   private String[] getConfigFileNames() {
+      File file = getRootFolder();
+      if (!file.isDirectory()) {
+         System.out.println("file.getAbsolutePath() = " + file.getAbsolutePath());
+      }
+      return file.list(new FilenameFilter() {
+         public boolean accept(File dir, String name) {
+            return name.indexOf("xml") > 0;
+         }
+      });
+   }
+
+   private File getRootFolder() {
+      File file = new File(CONFIG_ROOT);
+      //this is a hack. If the tests are run from core folder then following if should not be entered.
+      //otherwise assume we are runnin
+      if (!file.isDirectory()) {
+         file = new File("core/" + CONFIG_ROOT);
+      }
+      return file;
+   }
+
+
+   private static class InMemoryAppender extends AppenderSkeleton {
+      String[] TOLERABLE_WARNINGS =
+            {
+                  "Falling back to DummyTransactionManager from Infinispan",
+                  "Please set your max receive buffer in the OS correctly",
+            };
+      boolean foundUnknownWarning = false;
+
+      /**
+       * As this test runs in parallel with other tests tha also log information, we should disregard other possible
+       * warnings from other threads and only consider warnings issues within this test class's test.
+       *
+       * @see #isExpectedThread()
+       */
+      private Thread loggerThread = Thread.currentThread();
+
+      protected void append(LoggingEvent event) {
+         if (event.getLevel().equals(Level.WARN) && isExpectedThread()) {
+            boolean skipPrinting = false;
+            foundUnknownWarning = true;
+            for (String knownWarn : TOLERABLE_WARNINGS) {
+               if (event.getMessage().toString().indexOf(knownWarn) >= 0) {
+                  skipPrinting = true;
+                  foundUnknownWarning = false;
+               }
+            }
+
+            if (!skipPrinting) {
+               System.out.println("InMemoryAppender ****** " + event.getMessage().toString());
+               System.out.println("TOLERABLE_WARNINGS: " + Arrays.toString(TOLERABLE_WARNINGS));
+            }
+         }
+      }
+
+      public boolean requiresLayout() {
+         return false;
+      }
+
+      public void close() {
+         //do nothing
+      }
+
+      public boolean isFoundUnknownWarning() {
+         return foundUnknownWarning;
+      }
+
+      public boolean isExpectedThread() {
+         return loggerThread.equals(Thread.currentThread());
+      }
+   }
+}



More information about the infinispan-commits mailing list