Skip to content

Commit b8f8856

Browse files
authored
[ISSUE #10105] Fix ClassCastException in getLocks() method (#10106)
1 parent 6df8246 commit b8f8856

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

store/src/main/java/org/apache/rocketmq/store/lock/AdaptiveBackOffSpinLockImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.time.LocalTime;
2222
import java.util.ArrayList;
23+
import java.util.Collection;
2324
import java.util.HashMap;
2425
import java.util.List;
2526
import java.util.Map;
@@ -166,8 +167,8 @@ public void swap() {
166167
}
167168
}
168169

169-
public List<AdaptiveBackOffSpinLock> getLocks() {
170-
return (List<AdaptiveBackOffSpinLock>) this.locks.values();
170+
public Collection<AdaptiveBackOffSpinLock> getLocks() {
171+
return this.locks.values();
171172
}
172173

173174
public void setLocks(Map<String, AdaptiveBackOffSpinLock> locks) {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.rocketmq.store.lock;
19+
20+
import org.junit.Test;
21+
22+
import java.util.Collection;
23+
24+
import static org.junit.Assert.assertEquals;
25+
import static org.junit.Assert.assertNotNull;
26+
27+
public class AdaptiveBackOffSpinLockImplTest {
28+
29+
@Test
30+
public void testGetLocks() {
31+
AdaptiveBackOffSpinLockImpl lockImpl = new AdaptiveBackOffSpinLockImpl();
32+
Collection<AdaptiveBackOffSpinLock> locks = lockImpl.getLocks();
33+
assertEquals(2, locks.size());
34+
for (AdaptiveBackOffSpinLock lock : locks) {
35+
assertNotNull(lock);
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)