Skip to content

Commit 18135b9

Browse files
committed
cleanup exceptions
1 parent 2cad77d commit 18135b9

File tree

8 files changed

+88
-80
lines changed

8 files changed

+88
-80
lines changed

src/test/java/org/lmdbjava/ByteBufferProxyTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,24 @@ public void coverPrivateConstructor() throws Exception {
3737
}
3838

3939
@Test(expected = RuntimeException.class)
40-
public void fieldNeverFound() throws Exception {
40+
public void fieldNeverFound() {
4141
final Field f = findField(Exception.class, "notARealField");
4242
}
4343

4444
@Test
45-
public void fieldSuperclassScan() throws Exception {
45+
public void fieldSuperclassScan() {
4646
final Field f = findField(Exception.class, "detailMessage");
4747
assertThat(f, is(notNullValue()));
4848
}
4949

5050
@Test
51-
public void optimalAlwaysAvailable() throws Exception {
51+
public void optimalAlwaysAvailable() {
5252
final BufferProxy<ByteBuffer> v = PROXY_OPTIMAL;
5353
assertThat(v, is(notNullValue()));
5454
}
5555

5656
@Test
57-
public void safeCanBeForced() throws Exception {
57+
public void safeCanBeForced() {
5858
final BufferProxy<ByteBuffer> v = PROXY_SAFE;
5959
assertThat(v, is(notNullValue()));
6060
assertThat(v.getClass().getSimpleName(), startsWith("Reflect"));

src/test/java/org/lmdbjava/CursorTest.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import io.netty.buffer.ByteBuf;
1919
import java.io.File;
20+
import java.io.IOException;
2021
import java.nio.ByteBuffer;
2122
import org.agrona.MutableDirectBuffer;
2223
import static org.hamcrest.CoreMatchers.is;
@@ -51,7 +52,7 @@ public class CursorTest {
5152
public final TemporaryFolder tmp = new TemporaryFolder();
5253

5354
@Test(expected = ClosedException.class)
54-
public void closedCursorRejectsSubsequentGets() throws Exception {
55+
public void closedCursorRejectsSubsequentGets() {
5556
final Env<ByteBuffer> env = makeEnv(PROXY_OPTIMAL);
5657
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE);
5758
try (final Txn<ByteBuffer> txn = env.txnWrite()) {
@@ -62,7 +63,7 @@ public void closedCursorRejectsSubsequentGets() throws Exception {
6263
}
6364

6465
@Test
65-
public void count() throws Exception {
66+
public void count() {
6667
final Env<ByteBuffer> env = makeEnv(PROXY_OPTIMAL);
6768
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE, MDB_DUPSORT);
6869
try (final Txn<ByteBuffer> txn = env.txnWrite()) {
@@ -79,7 +80,7 @@ public void count() throws Exception {
7980
}
8081

8182
@Test
82-
public void cursorByteBufProxy() throws Exception {
83+
public void cursorByteBufProxy() {
8384
final Env<ByteBuf> env = makeEnv(new ByteBufProxy());
8485
final Dbi<ByteBuf> db = env.openDbi(DB_1, MDB_CREATE, MDB_DUPSORT);
8586
try (final Txn<ByteBuf> txn = env.txnWrite()) {
@@ -119,7 +120,7 @@ public void cursorByteBufProxy() throws Exception {
119120
}
120121

121122
@Test
122-
public void cursorByteBufferOptimal() throws Exception {
123+
public void cursorByteBufferOptimal() {
123124
final Env<ByteBuffer> env = makeEnv(PROXY_OPTIMAL);
124125
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE, MDB_DUPSORT);
125126
try (final Txn<ByteBuffer> txn = env.txnWrite()) {
@@ -159,7 +160,7 @@ public void cursorByteBufferOptimal() throws Exception {
159160
}
160161

161162
@Test
162-
public void cursorByteBufferSafe() throws Exception {
163+
public void cursorByteBufferSafe() {
163164
final Env<ByteBuffer> env = makeEnv(PROXY_SAFE);
164165
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE, MDB_DUPSORT);
165166
try (final Txn<ByteBuffer> txn = env.txnWrite()) {
@@ -199,7 +200,7 @@ public void cursorByteBufferSafe() throws Exception {
199200
}
200201

201202
@Test(expected = CommittedException.class)
202-
public void cursorCannotCloseIfTransactionCommitted() throws Exception {
203+
public void cursorCannotCloseIfTransactionCommitted() {
203204
final Env<ByteBuffer> env = makeEnv(PROXY_OPTIMAL);
204205
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE, MDB_DUPSORT);
205206
try (final Txn<ByteBuffer> txn = env.txnWrite()) {
@@ -214,7 +215,7 @@ public void cursorCannotCloseIfTransactionCommitted() throws Exception {
214215
}
215216

216217
@Test
217-
public void cursorMutableDirectBuffer() throws Exception {
218+
public void cursorMutableDirectBuffer() {
218219
final Env<MutableDirectBuffer> env = makeEnv(PROXY_MDB);
219220
final Dbi<MutableDirectBuffer> db = env.openDbi(DB_1, MDB_CREATE,
220221
MDB_DUPSORT);
@@ -255,7 +256,7 @@ public void cursorMutableDirectBuffer() throws Exception {
255256
}
256257

257258
@Test
258-
public void delete() throws Exception {
259+
public void delete() {
259260
final Env<ByteBuffer> env = makeEnv(PROXY_OPTIMAL);
260261
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE, MDB_DUPSORT);
261262
try (final Txn<ByteBuffer> txn = env.txnWrite()) {
@@ -275,7 +276,7 @@ public void delete() throws Exception {
275276
}
276277

277278
@Test
278-
public void renewTxRo() throws Exception {
279+
public void renewTxRo() {
279280
final Env<ByteBuffer> env = makeEnv(PROXY_OPTIMAL);
280281
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE);
281282

@@ -292,7 +293,7 @@ public void renewTxRo() throws Exception {
292293
}
293294

294295
@Test(expected = ReadOnlyRequiredException.class)
295-
public void renewTxRw() throws Exception {
296+
public void renewTxRw() {
296297
final Env<ByteBuffer> env = makeEnv(PROXY_OPTIMAL);
297298
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE);
298299
try (final Txn<ByteBuffer> txn = env.txnWrite()) {
@@ -304,7 +305,7 @@ public void renewTxRw() throws Exception {
304305
}
305306

306307
@Test
307-
public void repeatedCloseCausesNotError() throws Exception {
308+
public void repeatedCloseCausesNotError() {
308309
final Env<ByteBuffer> env = makeEnv(PROXY_OPTIMAL);
309310
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE, MDB_DUPSORT);
310311
try (final Txn<ByteBuffer> txn = env.txnWrite()) {
@@ -315,7 +316,7 @@ public void repeatedCloseCausesNotError() throws Exception {
315316
}
316317

317318
@Test
318-
public void reserve() throws Exception {
319+
public void reserve() {
319320
final Env<ByteBuffer> env = makeEnv(PROXY_OPTIMAL);
320321
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE, MDB_DUPSORT);
321322
try (final Txn<ByteBuffer> txn = env.txnWrite()) {
@@ -331,13 +332,17 @@ public void reserve() throws Exception {
331332
}
332333
}
333334

334-
private <T> Env<T> makeEnv(final BufferProxy<T> proxy) throws Exception {
335-
final Env<T> env = create(proxy);
336-
final File path = tmp.newFile();
337-
env.setMapSize(1_024 * 1_024);
338-
env.setMaxDbs(1);
339-
env.setMaxReaders(1);
340-
env.open(path, POSIX_MODE, MDB_NOSUBDIR);
341-
return env;
335+
private <T> Env<T> makeEnv(final BufferProxy<T> proxy) {
336+
try {
337+
final Env<T> env = create(proxy);
338+
final File path = tmp.newFile();
339+
env.setMapSize(1_024 * 1_024);
340+
env.setMaxDbs(1);
341+
env.setMaxReaders(1);
342+
env.open(path, POSIX_MODE, MDB_NOSUBDIR);
343+
return env;
344+
} catch (IOException e) {
345+
throw new RuntimeException(e);
346+
}
342347
}
343348
}

src/test/java/org/lmdbjava/DbiTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public void before() throws Exception {
6363

6464
@Test(expected = DbFullException.class)
6565
@SuppressWarnings("ResultOfObjectAllocationIgnored")
66-
public void dbOpenMaxDatabases() throws Exception {
66+
public void dbOpenMaxDatabases() {
6767
env.openDbi("db1 is OK", MDB_CREATE);
6868
env.openDbi("db2 is OK", MDB_CREATE);
6969
env.openDbi("db3 fails", MDB_CREATE);
@@ -85,7 +85,7 @@ public void keyExistsException() throws Exception {
8585
}
8686

8787
@Test
88-
public void putAbortGet() throws Exception {
88+
public void putAbortGet() {
8989
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE);
9090

9191
try (final Txn<ByteBuffer> txn = env.txnWrite()) {
@@ -99,7 +99,7 @@ public void putAbortGet() throws Exception {
9999
}
100100

101101
@Test
102-
public void putAndGetAndDeleteWithInternalTx() throws Exception {
102+
public void putAndGetAndDeleteWithInternalTx() {
103103
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE);
104104

105105
db.put(createBb(5), createBb(5));
@@ -116,7 +116,7 @@ public void putAndGetAndDeleteWithInternalTx() throws Exception {
116116
}
117117

118118
@Test
119-
public void putCommitGet() throws Exception {
119+
public void putCommitGet() {
120120
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE);
121121
try (final Txn<ByteBuffer> txn = env.txnWrite()) {
122122
db.put(txn, createBb(5), createBb(5));
@@ -131,7 +131,7 @@ public void putCommitGet() throws Exception {
131131
}
132132

133133
@Test
134-
public void putDelete() throws Exception {
134+
public void putDelete() {
135135
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE);
136136

137137
try (final Txn<ByteBuffer> txn = env.txnWrite()) {
@@ -144,7 +144,7 @@ public void putDelete() throws Exception {
144144
}
145145

146146
@Test
147-
public void putDuplicateDelete() throws Exception {
147+
public void putDuplicateDelete() {
148148
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE, MDB_DUPSORT);
149149

150150
try (final Txn<ByteBuffer> txn = env.txnWrite()) {
@@ -163,7 +163,7 @@ public void putDuplicateDelete() throws Exception {
163163
}
164164

165165
@Test
166-
public void putReserve() throws Exception {
166+
public void putReserve() {
167167
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE);
168168

169169
try (final Txn<ByteBuffer> txn = env.txnWrite()) {
@@ -180,7 +180,7 @@ public void putReserve() throws Exception {
180180
}
181181

182182
@Test(expected = MapFullException.class)
183-
public void testMapFullException() throws Exception {
183+
public void testMapFullException() {
184184
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE);
185185
try (final Txn<ByteBuffer> txn = env.txnWrite()) {
186186
final ByteBuffer v = allocateDirect(1_024 * 1_024 * 1_024);
@@ -189,7 +189,7 @@ public void testMapFullException() throws Exception {
189189
}
190190

191191
@Test
192-
public void testParallelWritesStress() throws Exception {
192+
public void testParallelWritesStress() {
193193
final Dbi<ByteBuffer> db = env.openDbi(DB_1, MDB_CREATE);
194194

195195
// Travis CI has 1.5 cores for legacy builds

0 commit comments

Comments
 (0)