~pbeaman/akiban-persistit/stress_test_refactor2

« back to all changes in this revision

Viewing changes to src/test/java/com/persistit/stress/Stress5.java

  • Committer: Peter Beaman
  • Date: 2012-06-11 16:30:00 UTC
  • Revision ID: pbeaman@akiban.com-20120611163000-kppkbxn3qqxqoold
Reorg packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * Copyright © 2005-2012 Akiban Technologies, Inc.  All rights reserved.
3
 
 *
4
 
 * This program is free software: you can redistribute it and/or modify
5
 
 * it under the terms of the GNU Affero General Public License as
6
 
 * published by the Free Software Foundation, version 3 (only) of the
7
 
 * License.
8
 
 *
9
 
 * This program is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
 * GNU Affero General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU Affero General Public License
15
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 
 * 
17
 
 * This program may also be available under different license terms. For more
18
 
 * information, see www.akiban.com or contact licensing@akiban.com.
19
 
 */
20
 
 
21
 
package com.persistit.stress;
22
 
 
23
 
import com.persistit.Exchange;
24
 
import com.persistit.Key;
25
 
import com.persistit.Value;
26
 
import com.persistit.exception.PersistitException;
27
 
import com.persistit.suite.TestResult;
28
 
import com.persistit.util.ArgParser;
29
 
 
30
 
public class Stress5 extends StressBase {
31
 
 
32
 
    public Stress5(String argsString) {
33
 
        super(argsString);
34
 
    }
35
 
 
36
 
    private final static String[] ARGS_TEMPLATE = { "repeat|int:1:0:1000000000|Repetitions",
37
 
            "count|int:10000:0:1000000000|Number of nodes to populate", "size|int:4029:10:10000000|Data record size",
38
 
            "splay0|int:12:1:1000|Splay 0", "splay1|int:3:1:1000|Splay 1", "splay2|int:7:1:1000|Splay 2", };
39
 
 
40
 
    int _splay0;
41
 
    int _splay1;
42
 
    int _splay2;
43
 
    int _size;
44
 
 
45
 
    @Override
46
 
    public void setUp() throws Exception {
47
 
        super.setUp();
48
 
        _ap = new ArgParser("com.persistit.Stress5", _args, ARGS_TEMPLATE);
49
 
        _total = _ap.getIntValue("count");
50
 
        _repeatTotal = _ap.getIntValue("repeat");
51
 
        _total = _ap.getIntValue("count");
52
 
 
53
 
        _splay0 = _ap.getIntValue("splay0");
54
 
        _splay1 = _ap.getIntValue("splay1");
55
 
        _splay2 = _ap.getIntValue("splay2");
56
 
        _size = _ap.getIntValue("size");
57
 
 
58
 
        try {
59
 
            // Exchange with Thread-private Tree
60
 
            _ex = getPersistit().getExchange("persistit", _rootName + _threadIndex, true);
61
 
            _exs = getPersistit().getExchange("persistit", "shared", true);
62
 
        } catch (final Exception ex) {
63
 
            handleThrowable(ex);
64
 
        }
65
 
    }
66
 
 
67
 
    /**
68
 
     * Implements tests with long keys and values of borderline length
69
 
     */
70
 
    @Override
71
 
    public void executeTest() {
72
 
        final Value value = new Value(getPersistit());
73
 
 
74
 
        final int baselineCount = 500;
75
 
        final int keyLength = 2041;
76
 
        final int maxDepth = keyLength - 10;
77
 
        final int minDepth = 20;
78
 
 
79
 
        for (_repeat = 0; (_repeat < _repeatTotal || isUntilStopped()) && !isStopped(); _repeat++) {
80
 
            try {
81
 
 
82
 
                setPhase("@");
83
 
                _ex.clear().remove(Key.GTEQ);
84
 
                addWork(1);
85
 
 
86
 
                setPhase("a");
87
 
                for (_count = 0; (_count < baselineCount) && !isStopped(); _count++) {
88
 
                    setupKey(_ex, keyLength, keyLength - 5, _count, _count, '5');
89
 
                    setupTestValue(_ex, _count, _size);
90
 
                    _ex.store();
91
 
                    addWork(1);
92
 
 
93
 
                }
94
 
                if (isStopped()) {
95
 
                    break;
96
 
                }
97
 
                setPhase("b");
98
 
                int depth;
99
 
                for (_count = 0, depth = maxDepth; (depth > minDepth) && !isStopped(); depth -= _splay1, _count++) {
100
 
                    setupKey(_ex, keyLength, depth, minDepth + (depth % _splay0), 55555 + depth, '5');
101
 
                    setupTestValue(_ex, 55555 + depth, _size);
102
 
                    _ex.store();
103
 
                    addWork(1);
104
 
 
105
 
                }
106
 
                if (isStopped()) {
107
 
                    break;
108
 
                }
109
 
 
110
 
                setPhase("c");
111
 
                for (_count = 0, depth = maxDepth; (depth > minDepth) && !isStopped(); depth -= _splay2, _count++) {
112
 
                    setupKey(_ex, keyLength, depth, minDepth + (depth % _splay0), 55555 - depth, '5');
113
 
                    setupTestValue(_ex, 55555 - depth, _size);
114
 
                    _ex.store();
115
 
                    addWork(1);
116
 
 
117
 
                }
118
 
                if (isStopped()) {
119
 
                    break;
120
 
                }
121
 
 
122
 
                setPhase("d");
123
 
                for (_count = 0, depth = maxDepth; (depth > minDepth) && !isStopped(); depth -= _splay1, _count++) {
124
 
                    setupKey(_ex, keyLength, depth, minDepth + (depth % _splay0), 55555 + depth, '5');
125
 
                    setupTestValue(_ex, 55555 + depth, _size);
126
 
                    _ex.fetch(value);
127
 
                    addWork(1);
128
 
 
129
 
                    compareValues(_ex.getValue(), value);
130
 
                    if (isStopped()) {
131
 
                        break;
132
 
                    }
133
 
                    _ex.remove();
134
 
                }
135
 
                if (isStopped()) {
136
 
                    break;
137
 
                }
138
 
 
139
 
                setPhase("e");
140
 
                for (_count = 0, depth = maxDepth; (depth > minDepth) && !isStopped(); depth -= _splay2, _count++) {
141
 
                    setupKey(_ex, keyLength, depth, minDepth + (depth % _splay0), 55555 - depth, '5');
142
 
                    setupTestValue(_ex, 55555 - depth, _size);
143
 
                    _ex.fetch(value);
144
 
                    addWork(1);
145
 
 
146
 
                    compareValues(_ex.getValue(), value);
147
 
                    if (isStopped()) {
148
 
                        break;
149
 
                    }
150
 
                    addWork(1);
151
 
                    if (!_ex.remove()) {
152
 
                        _result = new TestResult(false, "Failed to remove depth=" + depth);
153
 
                        forceStop();
154
 
                        break;
155
 
                    }
156
 
                }
157
 
                if (isStopped()) {
158
 
                    break;
159
 
                }
160
 
 
161
 
                setPhase("f");
162
 
                for (_count = 0; _count < baselineCount; _count++) {
163
 
                    setupKey(_ex, keyLength, keyLength - 5, _count, _count, '5');
164
 
                    addWork(1);
165
 
                    if (!_ex.remove()) {
166
 
                        System.out.println("Failed to remove counter=" + _count);
167
 
                    }
168
 
                }
169
 
 
170
 
                setPhase("g");
171
 
                _ex.clear();
172
 
                addWork(1);
173
 
 
174
 
                if (_ex.traverse(Key.GT, true)) {
175
 
                    System.out.println("Tree is not empty");
176
 
                }
177
 
 
178
 
            } catch (final PersistitException de) {
179
 
                handleThrowable(de);
180
 
            }
181
 
        }
182
 
    }
183
 
 
184
 
    private void setupKey(final Exchange ex, final int length, final int depth, final int a, final int b,
185
 
            final char fill) {
186
 
        _sb1.setLength(0);
187
 
        for (int i = 0; i < length; i++) {
188
 
            _sb1.append(fill);
189
 
        }
190
 
        fillLong(b, depth, 5, true);
191
 
        ex.clear().append(a).append(_sb1);
192
 
    }
193
 
 
194
 
}