Skip to content

Commit 52975f9

Browse files
Alexander PatrikalakisAlexander Patrikalakis
authored andcommitted
Use try with resources, move unnecessary members to local vars
Use try with resources Make some class members final Remove redundant throws declarations Use JanusGraphFactory.drop() instead of .clear() Inline some local variables and return Remove unused methods Make some members local Addresses JanusGraph#783, JanusGraph#781, JanusGraph#740. JanusGraph#819, JanusGraph#820 in part Signed-off-by: Alexander Patrikalakis <amcp@amazon.co.jp>
1 parent 6363057 commit 52975f9

80 files changed

Lines changed: 257 additions & 380 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

janusgraph-berkeleyje/src/main/java/org/janusgraph/diskstorage/berkeleyje/BerkeleyJEKeyValueStore.java

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,15 @@ public void acquireLock(StaticBuffer key, StaticBuffer expectedValue, StoreTrans
118118
@Override
119119
public RecordIterator<KeyValueEntry> getSlice(KVQuery query, StoreTransaction txh) throws BackendException {
120120
log.trace("beginning db={}, op=getSlice, tx={}", name, txh);
121-
Transaction tx = getTransaction(txh);
122-
Cursor cursor = null;
121+
final Transaction tx = getTransaction(txh);
123122
final StaticBuffer keyStart = query.getStart();
124123
final StaticBuffer keyEnd = query.getEnd();
125124
final KeySelector selector = query.getKeySelector();
126125
final List<KeyValueEntry> result = new ArrayList<>();
127-
try {
128-
DatabaseEntry foundKey = keyStart.as(ENTRY_FACTORY);
129-
DatabaseEntry foundData = new DatabaseEntry();
126+
final DatabaseEntry foundKey = keyStart.as(ENTRY_FACTORY);
127+
final DatabaseEntry foundData = new DatabaseEntry();
130128

131-
cursor = db.openCursor(tx, null);
129+
try (final Cursor cursor = db.openCursor(tx, null)) {
132130
OperationStatus status = cursor.getSearchKeyRange(foundKey, foundData, getLockMode(txh));
133131
//Iterate until given condition is satisfied or end of records
134132
while (status == OperationStatus.SUCCESS) {
@@ -146,40 +144,34 @@ public RecordIterator<KeyValueEntry> getSlice(KVQuery query, StoreTransaction tx
146144

147145
status = cursor.getNext(foundKey, foundData, getLockMode(txh));
148146
}
149-
log.trace("db={}, op=getSlice, tx={}, resultcount={}", name, txh, result.size());
150-
// log.trace("db={}, op=getSlice, tx={}, resultcount={}", name, txh, result.size(), new Throwable("getSlice trace"));
147+
} catch (Exception e) {
148+
throw new PermanentBackendException(e);
149+
}
151150

152-
return new RecordIterator<KeyValueEntry>() {
153-
private final Iterator<KeyValueEntry> entries = result.iterator();
151+
log.trace("db={}, op=getSlice, tx={}, resultcount={}", name, txh, result.size());
154152

155-
@Override
156-
public boolean hasNext() {
157-
return entries.hasNext();
158-
}
153+
return new RecordIterator<KeyValueEntry>() {
154+
private final Iterator<KeyValueEntry> entries = result.iterator();
159155

160-
@Override
161-
public KeyValueEntry next() {
162-
return entries.next();
163-
}
156+
@Override
157+
public boolean hasNext() {
158+
return entries.hasNext();
159+
}
164160

165-
@Override
166-
public void close() {
167-
}
161+
@Override
162+
public KeyValueEntry next() {
163+
return entries.next();
164+
}
168165

169-
@Override
170-
public void remove() {
171-
throw new UnsupportedOperationException();
172-
}
173-
};
174-
} catch (Exception e) {
175-
throw new PermanentBackendException(e);
176-
} finally {
177-
try {
178-
if (cursor != null) cursor.close();
179-
} catch (Exception e) {
180-
throw new PermanentBackendException(e);
166+
@Override
167+
public void close() {
181168
}
182-
}
169+
170+
@Override
171+
public void remove() {
172+
throw new UnsupportedOperationException();
173+
}
174+
};
183175
}
184176

185177
@Override

janusgraph-berkeleyje/src/main/java/org/janusgraph/diskstorage/berkeleyje/BerkeleyJETx.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,8 @@ public Transaction getTransaction() {
5050
return tx;
5151
}
5252

53-
void registerCursor(Cursor cursor) {
54-
Preconditions.checkArgument(cursor != null);
55-
synchronized (openCursors) {
56-
//TODO: attempt to remove closed cursors if there are too many
57-
openCursors.add(cursor);
58-
}
59-
}
60-
61-
private void closeOpenIterators() throws BackendException {
62-
for (Cursor cursor : openCursors) {
63-
cursor.close();
64-
}
53+
private void closeOpenIterators() {
54+
openCursors.forEach(Cursor::close);
6555
}
6656

6757
LockMode getLockMode() {

janusgraph-berkeleyje/src/test/java/org/janusgraph/diskstorage/berkeleyje/BerkeleyFixedLengthKCVSTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
import org.janusgraph.diskstorage.keycolumnvalue.keyvalue.OrderedKeyValueStoreManagerAdapter;
2323
import org.junit.Test;
2424

25-
import java.util.concurrent.ExecutionException;
26-
27-
2825
public class BerkeleyFixedLengthKCVSTest extends KeyColumnValueStoreTest {
2926

3027
public KeyColumnValueStoreManager openStorageManager() throws BackendException {
@@ -33,12 +30,12 @@ public KeyColumnValueStoreManager openStorageManager() throws BackendException {
3330
}
3431

3532
@Test @Override
36-
public void testConcurrentGetSlice() throws ExecutionException, InterruptedException, BackendException {
33+
public void testConcurrentGetSlice() {
3734

3835
}
3936

4037
@Test @Override
41-
public void testConcurrentGetSliceAndMutate() throws BackendException, ExecutionException, InterruptedException {
38+
public void testConcurrentGetSliceAndMutate() {
4239

4340
}
4441
}

janusgraph-berkeleyje/src/test/java/org/janusgraph/diskstorage/berkeleyje/BerkeleyVariableLengthKCVSTest.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
import org.janusgraph.diskstorage.keycolumnvalue.keyvalue.OrderedKeyValueStoreManagerAdapter;
2222
import org.junit.Test;
2323

24-
import java.util.concurrent.ExecutionException;
25-
26-
2724
public class BerkeleyVariableLengthKCVSTest extends KeyColumnValueStoreTest {
2825

2926
public KeyColumnValueStoreManager openStorageManager() throws BackendException {
@@ -32,12 +29,12 @@ public KeyColumnValueStoreManager openStorageManager() throws BackendException {
3229
}
3330

3431
@Test @Override
35-
public void testConcurrentGetSlice() throws ExecutionException, InterruptedException, BackendException {
32+
public void testConcurrentGetSlice() {
3633

3734
}
3835

3936
@Test @Override
40-
public void testConcurrentGetSliceAndMutate() throws BackendException, ExecutionException, InterruptedException {
37+
public void testConcurrentGetSliceAndMutate() {
4138

4239
}
4340
}

janusgraph-berkeleyje/src/test/java/org/janusgraph/graphdb/berkeleyje/BerkeleyGraphTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
package org.janusgraph.graphdb.berkeleyje;
1616

1717
import org.janusgraph.core.JanusGraphException;
18-
import org.janusgraph.core.util.JanusGraphCleanup;
18+
import org.janusgraph.core.JanusGraphFactory;
1919
import org.janusgraph.diskstorage.Backend;
20+
import org.janusgraph.diskstorage.BackendException;
2021
import org.janusgraph.diskstorage.configuration.ConfigOption;
2122
import org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration;
2223
import org.junit.Rule;
@@ -99,12 +100,11 @@ public void testConcurrentConsistencyEnforcement() {
99100
}
100101

101102
@Test
102-
public void testIDBlockAllocationTimeout()
103-
{
103+
public void testIDBlockAllocationTimeout() throws BackendException {
104104
config.set("ids.authority.wait-time", Duration.of(0L, ChronoUnit.NANOS));
105105
config.set("ids.renew-timeout", Duration.of(1L, ChronoUnit.MILLIS));
106106
close();
107-
JanusGraphCleanup.clear(graph);
107+
JanusGraphFactory.drop(graph);
108108
open(config);
109109
try {
110110
graph.addVertex();

janusgraph-cassandra/src/main/java/org/janusgraph/diskstorage/cassandra/embedded/CassandraEmbeddedStoreManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class CassandraEmbeddedStoreManager extends AbstractCassandraStoreManager
7373

7474
private final IRequestScheduler requestScheduler;
7575

76-
public CassandraEmbeddedStoreManager(Configuration config) throws BackendException {
76+
public CassandraEmbeddedStoreManager(Configuration config) {
7777
super(config);
7878

7979
String cassandraConfig = CASSANDRA_YAML_DEFAULT;
@@ -120,7 +120,6 @@ public String toString() {
120120
@Override
121121
public void close() {
122122
openStores.clear();
123-
CassandraDaemonWrapper.stop();
124123
}
125124

126125
@Override

janusgraph-cassandra/src/main/java/org/janusgraph/diskstorage/cassandra/thrift/CassandraThriftStoreManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ public boolean exists() throws BackendException {
470470
}
471471
}
472472

473-
private KsDef ensureKeyspaceExists(String keyspaceName) throws TException, BackendException {
473+
private KsDef ensureKeyspaceExists(String keyspaceName) throws BackendException {
474474
CTConnection connection = null;
475475

476476
try {

janusgraph-cassandra/src/test/java/org/janusgraph/diskstorage/cassandra/AbstractCassandraStoreTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public void testDisableCFCompressor() throws BackendException {
140140
}
141141

142142
@Test
143-
public void testTTLSupported() throws Exception {
143+
public void testTTLSupported() {
144144
StoreFeatures features = manager.getFeatures();
145145
assertTrue(features.hasCellTTL());
146146
}

janusgraph-cassandra/src/test/java/org/janusgraph/graphdb/CassandraGraphTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static void startCassandra() {
4545
}
4646

4747
@Test
48-
public void testHasTTL() throws Exception {
48+
public void testHasTTL() {
4949
assertTrue(features.hasCellTTL());
5050
}
5151

janusgraph-cassandra/src/test/java/org/janusgraph/graphdb/thrift/ThriftConnectionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class ThriftConnectionTest {
4646
private CTConnectionFactory.Config factoryConfig;
4747

4848
@Before
49-
public void setUp() throws Exception {
49+
public void setUp() {
5050
try {
5151
Config.setClientMode(true);
5252
Schema.instance.load(KSMetaData.newKeyspace("janusgraph", "SimpleStrategy", ImmutableMap.of("replication_factor", "1"), true));

0 commit comments

Comments
 (0)