Skip to content

Commit 872f37d

Browse files
authored
[ISSUE#2415] Delete the useless code (apache#2416)
1 parent 03c1f11 commit 872f37d

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

client/src/main/java/org/apache/rocketmq/client/common/ThreadLocalIndex.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,10 @@ public int getAndIncrement() {
2727
Integer index = this.threadLocalIndex.get();
2828
if (null == index) {
2929
index = Math.abs(random.nextInt());
30-
if (index < 0)
31-
index = 0;
3230
this.threadLocalIndex.set(index);
3331
}
3432

3533
index = Math.abs(index + 1);
36-
if (index < 0)
37-
index = 0;
38-
3934
this.threadLocalIndex.set(index);
4035
return index;
4136
}

client/src/test/java/org/apache/rocketmq/client/common/ThreadLocalIndexTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,11 @@ public void testGetAndIncrement() throws Exception {
2929
assertThat(localIndex.getAndIncrement()).isEqualTo(initialVal + 1);
3030
}
3131

32+
@Test
33+
public void testGetAndIncrement2() throws Exception {
34+
ThreadLocalIndex localIndex = new ThreadLocalIndex();
35+
int initialVal = localIndex.getAndIncrement();
36+
assertThat(initialVal >= 0);
37+
}
38+
3239
}

0 commit comments

Comments
 (0)