1 package org.apache.directmemory.cache;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 }