未验证 提交 872f37d9 编写于 作者: 有理想的程序员's avatar 有理想的程序员 提交者: GitHub

[ISSUE#2415] Delete the useless code (#2416)

上级 03c1f11d
...@@ -27,15 +27,10 @@ public class ThreadLocalIndex { ...@@ -27,15 +27,10 @@ public class ThreadLocalIndex {
Integer index = this.threadLocalIndex.get(); Integer index = this.threadLocalIndex.get();
if (null == index) { if (null == index) {
index = Math.abs(random.nextInt()); index = Math.abs(random.nextInt());
if (index < 0)
index = 0;
this.threadLocalIndex.set(index); this.threadLocalIndex.set(index);
} }
index = Math.abs(index + 1); index = Math.abs(index + 1);
if (index < 0)
index = 0;
this.threadLocalIndex.set(index); this.threadLocalIndex.set(index);
return index; return index;
} }
......
...@@ -29,4 +29,11 @@ public class ThreadLocalIndexTest { ...@@ -29,4 +29,11 @@ public class ThreadLocalIndexTest {
assertThat(localIndex.getAndIncrement()).isEqualTo(initialVal + 1); assertThat(localIndex.getAndIncrement()).isEqualTo(initialVal + 1);
} }
@Test
public void testGetAndIncrement2() throws Exception {
ThreadLocalIndex localIndex = new ThreadLocalIndex();
int initialVal = localIndex.getAndIncrement();
assertThat(initialVal >= 0);
}
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册