View Javadoc

1   package org.apache.directmemory.cache;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import com.carrotsearch.junitbenchmarks.AbstractBenchmark;
23  import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
24  import org.apache.directmemory.cache.Cache;
25  import org.apache.directmemory.measures.Monitor;
26  import org.apache.directmemory.measures.Ram;
27  import org.apache.directmemory.misc.DummyPojo;
28  import org.junit.AfterClass;
29  import org.junit.BeforeClass;
30  import org.junit.Ignore;
31  import org.junit.Test;
32  import org.slf4j.Logger;
33  import org.slf4j.LoggerFactory;
34  
35  import java.io.IOException;
36  import java.util.Random;
37  
38  import static org.junit.Assert.assertEquals;
39  
40  
41  @Ignore
42  public class TestCachePlusSerialization
43      extends AbstractBenchmark
44  {
45  
46      private static Logger logger = LoggerFactory.getLogger( TestCachePlusSerialization.class );
47  
48      Random rnd = new Random();
49  
50      @BeforeClass
51      public static void init()
52      {
53          logger.info( "test started" );
54          Cache.init( 1, Ram.Mb( 100 ) );
55      }
56  
57      @AfterClass
58      public static void end()
59          throws IOException
60      {
61          Cache.dump();
62          Monitor.dump();
63          Cache.close();
64          logger.info( "test ended" );
65      }
66  
67      @BenchmarkOptions( benchmarkRounds = 50000, warmupRounds = 0, concurrency = 1 )
68      @Test
69      public void basicBench()
70      {
71  
72          DummyPojo d = new DummyPojo( "test-" + rnd.nextInt( 100000 ), 1024 + rnd.nextInt( 1024 ) );
73          Cache.put( d.name, d );
74          DummyPojo d2 = (DummyPojo) Cache.retrieve( d.name );
75  
76          assertEquals( d.name, d2.name );
77  
78      }
79  
80  }