Author: tommaso
Date: Tue Jun 12 15:29:39 2012
New Revision: 1349391

URL: http://svn.apache.org/viewvc?rev=1349391&view=rev
Log:
[DIRECTMEMORY-89] - adapting solrconfig, reenabling integration test, fixing 
init() method of SolrOffHeapCache

Added:
    incubator/directmemory/trunk/integrations/solr/src/test/resources/solr/conf/
      - copied from r1349283, 
incubator/directmemory/trunk/integrations/solr/src/test/resources/solr/config/
Removed:
    
incubator/directmemory/trunk/integrations/solr/src/test/resources/solr/config/
Modified:
    
incubator/directmemory/trunk/integrations/solr/src/main/java/org/apache/directmemory/solr/SolrOffHeapCache.java
    
incubator/directmemory/trunk/integrations/solr/src/test/java/org/apache/directmemory/solr/SolrOffHeapIntegrationTest.java

Modified: 
incubator/directmemory/trunk/integrations/solr/src/main/java/org/apache/directmemory/solr/SolrOffHeapCache.java
URL: 
http://svn.apache.org/viewvc/incubator/directmemory/trunk/integrations/solr/src/main/java/org/apache/directmemory/solr/SolrOffHeapCache.java?rev=1349391&r1=1349390&r2=1349391&view=diff
==============================================================================
--- 
incubator/directmemory/trunk/integrations/solr/src/main/java/org/apache/directmemory/solr/SolrOffHeapCache.java
 (original)
+++ 
incubator/directmemory/trunk/integrations/solr/src/main/java/org/apache/directmemory/solr/SolrOffHeapCache.java
 Tue Jun 12 15:29:39 2012
@@ -89,15 +89,17 @@ public class SolrOffHeapCache<K, V>
     public Object init( Map args, Object persistence, CacheRegenerator 
regenerator )
     {
 
-
         Object buffers = args.get( "buffers" );
         String sizeStr = String.valueOf( args.get( "size" ) );
-        Integer capacity = Integer.parseInt( String.valueOf( args.get( 
"initialSize" ) ) );
+        final int limit = sizeStr == null ? 1024 : Integer.parseInt( sizeStr );
+        String initialSizeValue = (String) args.get( "initialSize" );
+        final int initialSize = Math.min( initialSizeValue == null ? 1024 : 
Integer.parseInt( initialSizeValue ), limit );
+
 
         cacheService = new DirectMemory<K, V>()
                         .setNumberOfBuffers( buffers != null ? 
Integer.valueOf( String.valueOf( buffers ) ) : 1 )
-                        .setInitialCapacity( Ram.Mb( Double.valueOf( capacity 
) / 512 ) )
-                        .setSize( Ram.Mb( Double.valueOf( sizeStr ) / 512 ) )
+                        .setInitialCapacity( Ram.Mb( Double.valueOf( 
initialSize ) / 512 ) )
+                        .setSize( Ram.Mb( limit / 512 ) )
                         .newCacheService();
 
         String serializerClassName = (String) args.get( "serializerClassName" 
);
@@ -111,7 +113,7 @@ public class SolrOffHeapCache<K, V>
             catch ( SerializerNotFoundException e )
             {
                 log.warn( "Serializer not found for class " + 
serializerClassName +
-                               ", falling back to the default serializer", e);
+                        ", falling back to the default serializer", e);
                 serializer = SerializerFactory.createNewSerializer();
             }
 
@@ -121,11 +123,8 @@ public class SolrOffHeapCache<K, V>
         state = State.CREATED;
         this.regenerator = regenerator;
         name = (String) args.get( "name" );
-        final int limit = sizeStr == null ? 1024 : Integer.parseInt( sizeStr );
-        String str = (String) args.get( "initialSize" );
-        final int initialSize = Math.min( str == null ? 1024 : 
Integer.parseInt( str ), limit );
-        str = (String) args.get( "autowarmCount" );
-        autowarmCount = str == null ? 0 : Integer.parseInt( str );
+        String autoWarmCount = (String) args.get( "autowarmCount" );
+        autowarmCount = autoWarmCount == null ? 0 : Integer.parseInt( 
autoWarmCount );
 
         description = "Solr OffHeap Cache(maxSize=" + limit + ", initialSize=" 
+ initialSize;
         if ( autowarmCount > 0 )

Modified: 
incubator/directmemory/trunk/integrations/solr/src/test/java/org/apache/directmemory/solr/SolrOffHeapIntegrationTest.java
URL: 
http://svn.apache.org/viewvc/incubator/directmemory/trunk/integrations/solr/src/test/java/org/apache/directmemory/solr/SolrOffHeapIntegrationTest.java?rev=1349391&r1=1349390&r2=1349391&view=diff
==============================================================================
--- 
incubator/directmemory/trunk/integrations/solr/src/test/java/org/apache/directmemory/solr/SolrOffHeapIntegrationTest.java
 (original)
+++ 
incubator/directmemory/trunk/integrations/solr/src/test/java/org/apache/directmemory/solr/SolrOffHeapIntegrationTest.java
 Tue Jun 12 15:29:39 2012
@@ -16,60 +16,47 @@
  */
 package org.apache.directmemory.solr;
 
-import static org.junit.Assert.assertTrue;
+import java.util.Map;
 
-import org.apache.directmemory.solr.SolrOffHeapCache;
-import org.apache.solr.request.LocalSolrQueryRequest;
-import org.apache.solr.util.TestHarness;
-import org.junit.AfterClass;
+import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.core.SolrInfoMBean;
 import org.junit.BeforeClass;
-import org.junit.Ignore;
 import org.junit.Test;
 
 /**
  */
 public class SolrOffHeapIntegrationTest
-{
-
-    private static SolrOffHeapCache<Object, Object> solrOffHeapCache;
-
-    private static TestHarness h;
+        extends SolrTestCaseJ4 {
 
     @BeforeClass
-    public static void setUp()
-    {
-        String data = "target/data/expand";
-        String config = SolrOffHeapCache.class.getResource( 
"/solr/config/solrconfig.xml" ).getFile();
-        String schema = SolrOffHeapCache.class.getResource( 
"/solr/config/schema.xml" ).getFile();
-        h = new TestHarness( data, config, schema );
-        solrOffHeapCache = new SolrOffHeapCache<Object, Object>();
-    }
-
-    @AfterClass
-    public static void tearDown()
-    {
-        // FIXME restore this when issue with static is fixed
-        //solrOffHeapCache.getCacheService().clear();
+    public static void beforeClass() throws Exception {
+        initCore("solrconfig.xml", "schema.xml", 
getFile("solr").getAbsolutePath());
     }
 
     @Test
-    @Ignore // FIXME need TomNaso help - now I see why he needed a static 
CacheService reference
-    public void testSimpleQuery()
+    public void testSingleQuery()
         throws Exception
     {
 
         // add a doc to Solr
-        h.validateAddDoc( "id", "1", "text", "something is happening here" );
-
+        assertU(adoc("id", "1", "text", "something is happening here"));
+        assertU(commit());
         // make the query
-        LocalSolrQueryRequest request = h.getRequestFactory( "standard", 0, 10 
).makeRequest( "q", "something" );
-        String response = h.query( "standard", request );
-        assertTrue( response != null );
-        assertTrue( !response.contains( "error" ) );
+        assertQ(req("text:something"), "//*[@numFound='1']");
 
-        // check the cache has been hit
-        assertTrue( solrOffHeapCache.getCacheService().entries() > 0 );
+        Map<String, SolrInfoMBean> infoRegistry = 
h.getCore().getInfoRegistry();
 
+        // check the stats of the queryResultCache
+        SolrInfoMBean solrInfoMBean = infoRegistry.get("queryResultCache");
+        NamedList stats = solrInfoMBean.getStatistics();
+        Long hits = (Long) stats.get("hits");
+        assertEquals(Long.valueOf(0l), hits);
+        Long lookups = (Long) stats.get("lookups");
+        assertEquals(Long.valueOf(1l), lookups);
+        Long inserts = (Long) stats.get("inserts");
+        assertEquals(Long.valueOf(1l), inserts);
 
     }
+
 }


Reply via email to