Skip to content

Commit

Permalink
Merge d5cee4f into 03c1f11
Browse files Browse the repository at this point in the history
  • Loading branch information
lovelife-li committed Nov 9, 2020
2 parents 03c1f11 + d5cee4f commit 40e3718
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Expand Up @@ -27,15 +27,10 @@ public int getAndIncrement() {
Integer index = this.threadLocalIndex.get();
if (null == index) {
index = Math.abs(random.nextInt());
if (index < 0)
index = 0;
this.threadLocalIndex.set(index);
}

index = Math.abs(index + 1);
if (index < 0)
index = 0;

this.threadLocalIndex.set(index);
return index;
}
Expand Down
Expand Up @@ -29,4 +29,11 @@ public void testGetAndIncrement() throws Exception {
assertThat(localIndex.getAndIncrement()).isEqualTo(initialVal + 1);
}

@Test
public void testGetAndIncrement2() throws Exception {
ThreadLocalIndex localIndex = new ThreadLocalIndex();
int initialVal = localIndex.getAndIncrement();
assertThat(initialVal >= 0);
}

}

0 comments on commit 40e3718

Please sign in to comment.