FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-279 Address GH code fix suggestions · lmdbjava/lmdbjava@8c001e6 · GitHub

Commit 8c001e6

Browse files
committed
gh-279 Address GH code fix suggestions
1 parent ed0df73 commit 8c001e6

4 files changed

Lines changed: 27 additions & 28 deletions

File tree

‎src/main/java/org/lmdbjava/SimpleRefCounter.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public boolean isClosed() {
3232
return counter.get() == CLOSED_VALUE;
3333
}
3434

35+
@Override
3536
public RefCounterReleaser acquire() {
3637
final int newVal =
3738
counter.updateAndGet(currVal -> currVal == CLOSED_VALUE ? currVal : currVal + 1);

‎src/main/java/org/lmdbjava/SynchronisedRefCounter.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public boolean isClosed() {
3333
}
3434
}
3535

36+
@Override
3637
public RefCounterReleaser acquire() {
3738
synchronized (this) {
3839
if (isClosed) {

‎src/test/java/org/lmdbjava/CursorIterableTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private void populateDatabase(final Dbi<ByteBuffer> dbi) {
129129

130130
@Test
131131
void testPopulate() {
132-
final Dbi<ByteBuffer> db = getDb();
132+
getDb();
133133
}
134134

135135
@Test

‎src/test/java/org/lmdbjava/RefCounterTest.java‎

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
public class RefCounterTest {
4646
private static final int PROCESSOR_COUNT = Runtime.getRuntime().availableProcessors();
4747
private final int iterations = 20_000_000;
48-
private final int threadCount = PROCESSOR_COUNT;
48+
private final int processorCount = PROCESSOR_COUNT;
4949

5050
/**
5151
* @return A {@link Stream} of all {@link RefCounter}s for {@link ParameterizedTest}s.
@@ -78,7 +78,7 @@ public void perfTest() {
7878
final int round = i;
7979
// Run tests with all available processors
8080
System.out.println(
81-
"Multi-threaded (" + threadCount + " threads) tests ---------------------------------");
81+
"Multi-threaded (" + processorCount + " threads) tests ---------------------------------");
8282

8383
System.out.println("Round: " + round + " " + StripedRefCounter.class.getSimpleName());
8484
IntStream.of(1, 16, 32, 64, 128, 256)
@@ -208,17 +208,17 @@ void testRefCounters(final RefCounter refCounter) {
208208
@MethodSource("multiThreadedRefCounterProvider")
209209
void multipleThreads(final RefCounter refCounter) {
210210
final int iterations = 1000;
211-
final AtomicInteger[] callCounts = new AtomicInteger[threadCount];
212-
for (int i = 0; i < threadCount; i++) {
211+
final AtomicInteger[] callCounts = new AtomicInteger[processorCount];
212+
for (int i = 0; i < processorCount; i++) {
213213
callCounts[i] = new AtomicInteger();
214214
}
215-
final CountDownLatch countDownLatch = new CountDownLatch(threadCount);
215+
final CountDownLatch countDownLatch = new CountDownLatch(processorCount);
216216
//noinspection resource ExecutorService does not implement AutoCloseable in Java8
217-
final ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
217+
final ExecutorService executorService = Executors.newFixedThreadPool(processorCount);
218218
try {
219219

220220
final CompletableFuture<?>[] futures =
221-
IntStream.range(0, threadCount)
221+
IntStream.range(0, processorCount)
222222
.boxed()
223223
.map(
224224
i ->
@@ -255,20 +255,20 @@ void multipleThreads_delayedRelease(final RefCounter refCounter) {
255255
final Queue<RefCounter.RefCounterReleaser> releasers;
256256

257257
//noinspection resource ExecutorService does not implement AutoCloseable in Java8
258-
final ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
259-
final ExecutorService executorService2 = Executors.newFixedThreadPool(threadCount);
258+
final ExecutorService executorService = Executors.newFixedThreadPool(processorCount);
259+
final ExecutorService executorService2 = Executors.newFixedThreadPool(processorCount);
260260

261261
try {
262-
callCounts = new AtomicInteger[threadCount];
263-
for (int i = 0; i < threadCount; i++) {
262+
callCounts = new AtomicInteger[processorCount];
263+
for (int i = 0; i < processorCount; i++) {
264264
callCounts[i] = new AtomicInteger();
265265
}
266-
final CountDownLatch countDownLatch = new CountDownLatch(threadCount);
266+
final CountDownLatch countDownLatch = new CountDownLatch(processorCount);
267267

268268
releasers = new ConcurrentLinkedQueue<>();
269269
final Queue<CompletableFuture<?>> futures = new ConcurrentLinkedQueue<>();
270270

271-
IntStream.range(0, threadCount)
271+
IntStream.range(0, processorCount)
272272
.boxed()
273273
.map(
274274
i ->
@@ -297,7 +297,7 @@ void multipleThreads_delayedRelease(final RefCounter refCounter) {
297297
executorService.shutdown();
298298
}
299299

300-
assertRefCount(refCounter, threadCount * iterations);
300+
assertRefCount(refCounter, processorCount * iterations);
301301

302302
for (AtomicInteger callCount : callCounts) {
303303
assertThat(callCount).hasValue(iterations);
@@ -338,7 +338,7 @@ void testImmediateClose(final RefCounter refCounter) {
338338
@MethodSource("multiThreadedRefCounterProvider")
339339
void testBehaviour(final RefCounter refCounter) throws InterruptedException {
340340
final Random random = new Random();
341-
final int threadCount = this.threadCount - 1;
341+
final int threadCount = this.processorCount - 1;
342342
//noinspection resource ExecutorService does not implement AutoCloseable in Java8
343343
final ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
344344
try {
@@ -347,7 +347,6 @@ void testBehaviour(final RefCounter refCounter) throws InterruptedException {
347347
final AtomicReference<Object> mockEnv = new AtomicReference<>();
348348

349349
for (int k = 0; k < rounds; k++) {
350-
final int round = k;
351350

352351
// Reset the env
353352
mockEnv.set(new Object());
@@ -401,7 +400,6 @@ void testBehaviour(final RefCounter refCounter) throws InterruptedException {
401400
// Give the other threads a chance to get underway
402401
TestUtils.sleep(200 + random.nextInt(200));
403402
final AtomicBoolean didClose = new AtomicBoolean(false);
404-
int closeCallCount = 0;
405403
final AtomicInteger onCloseCallCount = new AtomicInteger();
406404
while (!didClose.get()) {
407405
try {
@@ -450,7 +448,7 @@ void testBehaviour(final RefCounter refCounter) throws InterruptedException {
450448
@MethodSource("multiThreadedRefCounterProvider")
451449
void testGetCount(final RefCounter refCounter) throws InterruptedException {
452450
final Random random = new Random();
453-
final int threadCount = this.threadCount - 1;
451+
final int threadCount = this.processorCount - 1;
454452
//noinspection resource ExecutorService does not implement AutoCloseable in Java8
455453
final ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
456454
try {
@@ -599,13 +597,13 @@ public void noOpRefCounter() {
599597

600598
private void doNoOpRefCounter() {
601599
final AtomicReference<Instant> startTime = new AtomicReference<>(null);
602-
final CompletableFuture<?>[] futures = new CompletableFuture[threadCount];
600+
final CompletableFuture<?>[] futures = new CompletableFuture[processorCount];
603601
final NoOpRefCounter refCounter = new NoOpRefCounter();
604-
final CountDownLatch startLatch = new CountDownLatch(threadCount);
605-
final ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
602+
final CountDownLatch startLatch = new CountDownLatch(processorCount);
603+
final ExecutorService executorService = Executors.newFixedThreadPool(processorCount);
606604
try {
607-
final int iterationsPerThread = iterations / threadCount;
608-
for (int i = 0; i < threadCount; i++) {
605+
final int iterationsPerThread = iterations / processorCount;
606+
for (int i = 0; i < processorCount; i++) {
609607
futures[i] =
610608
CompletableFuture.runAsync(
611609
() -> {
@@ -632,9 +630,8 @@ private void doNoOpRefCounter() {
632630
}
633631
CompletableFuture.allOf(futures).join();
634632

635-
final Duration duration = Duration.between(startTime.get(), Instant.now());
636-
final long iterationsPerSec = Math.round((double) iterations / duration.toMillis() * 1000);
637-
633+
// final Duration duration = Duration.between(startTime.get(), Instant.now());
634+
// final long iterationsPerSec = Math.round((double) iterations / duration.toMillis() * 1000);
638635
// System.out.println(
639636
// "All Finished"
640637
// + ", threads: "
@@ -652,7 +649,7 @@ private void doNoOpRefCounter() {
652649
}
653650

654651
private void runPerfTest(int stripes, final RefCounter refCounter) {
655-
runPerfTest(stripes, threadCount, refCounter);
652+
runPerfTest(stripes, processorCount, refCounter);
656653
}
657654

658655
private void runPerfTest(int stripes, final int threadCount, final RefCounter refCounter) {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL