~ubuntu-branches/ubuntu/trusty/ehcache/trusty

« back to all changes in this revision

Viewing changes to src/test/perf/net/sf/ehcache/DiskStorePerfTest.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2013-05-06 14:53:07 UTC
  • mfrom: (1.1.7) (2.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130506145307-v5bhw5yu70re00l3
Tags: 2.6.7-1
* Team upload.
* New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
import net.sf.ehcache.config.CacheConfiguration;
4
4
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
 
5
import net.sf.ehcache.util.RetryAssert;
5
6
import org.junit.After;
6
7
import org.junit.Ignore;
7
8
import org.junit.Test;
9
10
import org.slf4j.LoggerFactory;
10
11
 
11
12
import java.util.Random;
 
13
import java.util.concurrent.Callable;
 
14
import java.util.concurrent.TimeUnit;
12
15
 
13
 
import static org.junit.Assert.assertEquals;
14
 
import static org.junit.Assert.assertTrue;
 
16
import static org.hamcrest.core.IsEqual.equalTo;
 
17
import static org.hamcrest.number.OrderingComparison.greaterThan;
 
18
import static org.hamcrest.number.OrderingComparison.greaterThanOrEqualTo;
 
19
import static org.hamcrest.number.OrderingComparison.lessThan;
 
20
import static org.junit.Assert.assertThat;
15
21
import static org.junit.Assert.fail;
16
22
 
17
23
/**
20
26
public class DiskStorePerfTest extends AbstractCachePerfTest {
21
27
 
22
28
    private static final Logger LOG = LoggerFactory.getLogger(DiskStorePerfTest.class.getName());
23
 
    private static final int ELEMENT_ON_DISK_SIZE = 1270;
24
29
    private CacheManager manager2;
25
30
 
26
31
    /**
54
59
        }
55
60
        long time = stopWatch.getElapsedTime();
56
61
        LOG.info("time: " + time);
57
 
        assertTrue(4 < time);
 
62
        //XXX this assertion is nonsensical - what is it here for?
 
63
        assertThat(time, greaterThan(4L));
58
64
    }
59
65
 
60
66
 
65
71
     */
66
72
    @Test
67
73
    public void testOverflowToDiskWithLargeNumberofCacheEntriesAndGets() throws Exception {
68
 
 
69
 
        //Set size so the second element overflows to disk.
70
 
        //Cache cache = new Cache("test", 1000, MemoryStoreEvictionPolicy.LRU, true, null, true, 500, 500, false, 60, null);
71
 
        Cache cache = new Cache(new CacheConfiguration("test", 1000)
 
74
        final int ELEMENTS = 100000;
 
75
        final Cache cache = new Cache(new CacheConfiguration("test", 1000)
72
76
            .memoryStoreEvictionPolicy("LRU")
73
77
            .eternal(true)
74
78
            .overflowToDisk(true)
75
 
            .timeToLiveSeconds(1)
76
79
            .diskAccessStripes(5)
77
80
            .diskExpiryThreadIntervalSeconds(60));
78
81
        manager.addCache(cache);
79
82
        Random random = new Random();
80
83
        StopWatch stopWatch = new StopWatch();
81
 
        for (int i = 0; i < 100000; i++) {
82
 
            cache.put(new Element("" + i,
 
84
        for (int i = 0; i < ELEMENTS; i++) {
 
85
            cache.put(new Element(Integer.toString(i),
83
86
                "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
84
87
                + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
85
88
                + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
86
89
                + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
87
90
                + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
88
91
 
89
 
            cache.get("" + random.nextInt(100000));
 
92
            cache.get(Integer.toString(random.nextInt(i + 1)));
90
93
        }
91
94
 
92
 
 
 
95
        RetryAssert.assertBy(10, TimeUnit.SECONDS, new Callable<Integer>() {
 
96
            @Override
 
97
            public Integer call() throws Exception {
 
98
                return cache.getDiskStoreSize();
 
99
            }
 
100
        }, equalTo(ELEMENTS));
 
101
        assertThat(cache.getSize(), equalTo(ELEMENTS));
 
102
        
93
103
        long elapsed = stopWatch.getElapsedTime();
94
 
        LOG.info("Elapsed time: " + elapsed / 1000);
95
 
        Thread.sleep(500);
96
 
        assertEquals(100000, cache.getSize());
97
 
        assertTrue(23 < elapsed);
98
 
        //Some entries may be in the Memory Store and Disk Store. cache.getSize removes dupes. a look at the
99
 
        //disk store size directly does not.
100
 
        assertTrue(99000 <= cache.getDiskStoreSize());
 
104
        LOG.info("Elapsed time: " + elapsed);
101
105
    }
102
106
 
103
107
    /**
126
130
        Cache cache = new Cache("test", 1000, MemoryStoreEvictionPolicy.LRU, true, null, true, 500, 500, false, 1, null);
127
131
        manager.addCache(cache);
128
132
        StopWatch stopWatch = new StopWatch();
129
 
        int i = 0;
130
 
        int j = 0;
131
 
        Integer index = null;
 
133
        int index = 0;
132
134
        try {
133
 
            for (; i < 100; i++) {
134
 
                for (j = 0; j < 100000; j++) {
135
 
                    index = Integer.valueOf(((1000000 * i) + j));
136
 
                    cache.put(new Element(index,
 
135
            for (int i = 0; i < 100; i++) {
 
136
                for (int j = 0; j < 100000; j++) {
 
137
                    index = (1000000 * i) + j;
 
138
                    cache.put(new Element(Integer.valueOf(index),
137
139
                            "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
138
140
                                    + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
139
141
                                    + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
149
151
            fail();
150
152
        } catch (OutOfMemoryError e) {
151
153
            LOG.info("All heap consumed after " + index + " entries created.");
152
 
            int expectedMax = 3090000;
153
 
            assertTrue("Achieved " + index.intValue() + " which was less than the expected value of " + expectedMax,
154
 
                    index.intValue() >= expectedMax);
 
154
            assertThat(index, greaterThanOrEqualTo(3090000));
155
155
        }
156
156
    }
157
157
 
170
170
     * put 13, get 19
171
171
     *
172
172
     */
173
 
    //@Test
 
173
    @Test
 
174
    @Ignore
174
175
    public void testLargePutGetPerformanceWithOverflowToDisk() throws Exception {
175
176
 
176
177
        Cache cache = new Cache("test", 1000, MemoryStoreEvictionPolicy.LRU, true, null, true, 500, 500, false, 10000, null);
193
194
        long elapsed = stopWatch.getElapsedTime();
194
195
        long putTime = ((elapsed / 1000) - 10);
195
196
        LOG.info("Put Elapsed time: " + putTime);
196
 
        assertTrue(putTime < 20);
 
197
        assertThat(putTime, lessThan(20L));
197
198
 
198
199
        //wait for Disk Store to finish spooling
199
200
        while (cache.getStore().bufferFull()) {
212
213
        int time = (int) ((getElapsedTime - getStart) / 1000);
213
214
        LOG.info("Get Elapsed time: " + time);
214
215
 
215
 
        assertTrue(time < 180);
216
 
 
217
 
 
 
216
        assertThat(time, lessThan(180));
218
217
    }
219
218
 
220
219
    /**