Skip to content

Commit 2d7cd69

Browse files
authored
Remove raw typing in dummy pool classes (#18785)
* Dummy blocking pool generics * DummyBlockingPool * Test cases * Use integers to avoid imports
1 parent 22990f2 commit 2d7cd69

File tree

4 files changed

+103
-9
lines changed

4 files changed

+103
-9
lines changed

processing/src/main/java/org/apache/druid/collections/DummyBlockingPool.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@
2222
import java.util.List;
2323

2424
/**
25-
* BlockingPool with 0 maxSize, all take*() methods immediately throw {@link UnsupportedOperationException}.
25+
* BlockingPool with 0 maxSize, all {@code takeBatch} methods immediately throw {@link UnsupportedOperationException}.
2626
*/
27-
public final class DummyBlockingPool<T> implements BlockingPool<T>
27+
public final class DummyBlockingPool implements BlockingPool<Object>
2828
{
2929
private static final DummyBlockingPool INSTANCE = new DummyBlockingPool();
3030

3131
@SuppressWarnings("unchecked")
3232
public static <T> BlockingPool<T> instance()
3333
{
34-
return INSTANCE;
34+
return (BlockingPool<T>) INSTANCE;
3535
}
3636

3737
private DummyBlockingPool()
@@ -45,13 +45,13 @@ public int maxSize()
4545
}
4646

4747
@Override
48-
public List<ReferenceCountingResourceHolder<T>> takeBatch(int elementNum, long timeoutMs)
48+
public List<ReferenceCountingResourceHolder<Object>> takeBatch(int elementNum, long timeoutMs)
4949
{
5050
throw new UnsupportedOperationException();
5151
}
5252

5353
@Override
54-
public List<ReferenceCountingResourceHolder<T>> takeBatch(int elementNum)
54+
public List<ReferenceCountingResourceHolder<Object>> takeBatch(int elementNum)
5555
{
5656
throw new UnsupportedOperationException();
5757
}

processing/src/main/java/org/apache/druid/collections/DummyNonBlockingPool.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@
2020
package org.apache.druid.collections;
2121

2222
/**
23-
* NonBlockingPool which is not able to allocate objects, {@link #take()} throws {@link UnsupportedOperationException}.
23+
* NonBlockingPool that cannot allocate objects, {@link #take()} throws {@link UnsupportedOperationException}.
2424
*/
25-
public final class DummyNonBlockingPool<T> implements NonBlockingPool<T>
25+
public final class DummyNonBlockingPool implements NonBlockingPool<Object>
2626
{
2727
private static final DummyNonBlockingPool INSTANCE = new DummyNonBlockingPool();
2828

2929
@SuppressWarnings("unchecked")
3030
public static <T> NonBlockingPool<T> instance()
3131
{
32-
return INSTANCE;
32+
return (NonBlockingPool<T>) INSTANCE;
3333
}
3434

3535
private DummyNonBlockingPool()
3636
{
3737
}
3838

3939
@Override
40-
public ResourceHolder<T> take()
40+
public ResourceHolder<Object> take()
4141
{
4242
throw new UnsupportedOperationException();
4343
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.druid.collections;
21+
22+
import org.junit.jupiter.api.Assertions;
23+
import org.junit.jupiter.api.Test;
24+
25+
public class DummyBlockingPoolTest
26+
{
27+
@Test
28+
public void testSingletonInstance()
29+
{
30+
final BlockingPool<Object> p1 = DummyBlockingPool.instance();
31+
final BlockingPool<Integer> p2 = DummyBlockingPool.instance();
32+
Assertions.assertSame(p1, p2);
33+
}
34+
35+
@Test
36+
public void testMaxSizeAndMetricsAreZero()
37+
{
38+
final BlockingPool<Integer> pool = DummyBlockingPool.instance();
39+
Assertions.assertEquals(0, pool.maxSize());
40+
Assertions.assertEquals(0, pool.getPendingRequests());
41+
Assertions.assertEquals(0, pool.getUsedResourcesCount());
42+
}
43+
44+
@Test
45+
public void testTakeBatchThrows()
46+
{
47+
final BlockingPool<Integer> pool = DummyBlockingPool.instance();
48+
Assertions.assertThrows(UnsupportedOperationException.class, () -> pool.takeBatch(1));
49+
Assertions.assertThrows(UnsupportedOperationException.class, () -> pool.takeBatch(1, 10L));
50+
}
51+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.druid.collections;
21+
22+
import org.junit.jupiter.api.Assertions;
23+
import org.junit.jupiter.api.Test;
24+
25+
public class DummyNonBlockingPoolTest
26+
{
27+
@Test
28+
public void testSingletonInstance()
29+
{
30+
final NonBlockingPool<Object> p1 = DummyNonBlockingPool.instance();
31+
final NonBlockingPool<Integer> p2 = DummyNonBlockingPool.instance();
32+
Assertions.assertSame(p1, p2);
33+
}
34+
35+
@Test
36+
public void testTakeThrows()
37+
{
38+
final NonBlockingPool<Integer> pool = DummyNonBlockingPool.instance();
39+
Assertions.assertThrows(UnsupportedOperationException.class, pool::take);
40+
}
41+
}
42+
43+

0 commit comments

Comments
 (0)