|
64 | 64 | import static org.mockito.Mockito.mock; |
65 | 65 | import static org.mockito.Mockito.when; |
66 | 66 |
|
67 | | -public class BlockHashTests extends ESTestCase { |
68 | | - |
69 | | - final CircuitBreaker breaker = new MockBigArrays.LimitedBreaker("esql-test-breaker", ByteSizeValue.ofGb(1)); |
70 | | - final BigArrays bigArrays = new MockBigArrays(PageCacheRecycler.NON_RECYCLING_INSTANCE, mockBreakerService(breaker)); |
71 | | - final MockBlockFactory blockFactory = new MockBlockFactory(breaker, bigArrays); |
| 67 | +public class BlockHashTests extends BlockHashTestCase { |
72 | 68 |
|
73 | 69 | @ParametersFactory |
74 | 70 | public static List<Object[]> params() { |
@@ -1219,86 +1215,6 @@ public void close() { |
1219 | 1215 | } |
1220 | 1216 | } |
1221 | 1217 |
|
1222 | | - /** |
1223 | | - * Replicate the existing csv test, using sample_data.csv |
1224 | | - */ |
1225 | | - public void testCategorizeRaw() { |
1226 | | - final Page page; |
1227 | | - final int positions = 7; |
1228 | | - try (BytesRefBlock.Builder builder = blockFactory.newBytesRefBlockBuilder(positions)) { |
1229 | | - builder.appendBytesRef(new BytesRef("Connected to 10.1.0.1")); |
1230 | | - builder.appendBytesRef(new BytesRef("Connection error")); |
1231 | | - builder.appendBytesRef(new BytesRef("Connection error")); |
1232 | | - builder.appendBytesRef(new BytesRef("Connection error")); |
1233 | | - builder.appendBytesRef(new BytesRef("Disconnected")); |
1234 | | - builder.appendBytesRef(new BytesRef("Connected to 10.1.0.2")); |
1235 | | - builder.appendBytesRef(new BytesRef("Connected to 10.1.0.3")); |
1236 | | - page = new Page(builder.build()); |
1237 | | - } |
1238 | | - // final int emitBatchSize = between(positions, 10 * 1024); |
1239 | | - try ( |
1240 | | - BlockHash hash = new CategorizeRawBlockHash( |
1241 | | - blockFactory, |
1242 | | - 0, |
1243 | | - true, |
1244 | | - new CategorizationAnalyzer( |
1245 | | - // TODO: should be the same analyzer as used in Production |
1246 | | - new CustomAnalyzer( |
1247 | | - TokenizerFactory.newFactory("whitespace", WhitespaceTokenizer::new), |
1248 | | - new CharFilterFactory[0], |
1249 | | - new TokenFilterFactory[0] |
1250 | | - ), |
1251 | | - true |
1252 | | - ), |
1253 | | - new TokenListCategorizer.CloseableTokenListCategorizer( |
1254 | | - new CategorizationBytesRefHash(new BytesRefHash(2048, blockFactory.bigArrays())), |
1255 | | - CategorizationPartOfSpeechDictionary.getInstance(), |
1256 | | - 0.70f |
1257 | | - ) |
1258 | | - ); |
1259 | | - ) { |
1260 | | - hash.add(page, new GroupingAggregatorFunction.AddInput() { |
1261 | | - @Override |
1262 | | - public void add(int positionOffset, IntBlock groupIds) { |
1263 | | - groupIds.incRef(); |
1264 | | - assertEquals(groupIds.getPositionCount(), positions); |
1265 | | - |
1266 | | - assertEquals(0, groupIds.getInt(0)); |
1267 | | - assertEquals(1, groupIds.getInt(1)); |
1268 | | - assertEquals(1, groupIds.getInt(2)); |
1269 | | - assertEquals(1, groupIds.getInt(3)); |
1270 | | - assertEquals(2, groupIds.getInt(4)); |
1271 | | - assertEquals(0, groupIds.getInt(5)); |
1272 | | - assertEquals(0, groupIds.getInt(6)); |
1273 | | - } |
1274 | | - |
1275 | | - @Override |
1276 | | - public void add(int positionOffset, IntVector groupIds) { |
1277 | | - groupIds.incRef(); |
1278 | | - assertEquals(groupIds.getPositionCount(), positions); |
1279 | | - |
1280 | | - assertEquals(0, groupIds.getInt(0)); |
1281 | | - assertEquals(1, groupIds.getInt(1)); |
1282 | | - assertEquals(1, groupIds.getInt(2)); |
1283 | | - assertEquals(1, groupIds.getInt(3)); |
1284 | | - assertEquals(2, groupIds.getInt(4)); |
1285 | | - assertEquals(0, groupIds.getInt(5)); |
1286 | | - assertEquals(0, groupIds.getInt(6)); |
1287 | | - } |
1288 | | - |
1289 | | - @Override |
1290 | | - public void close() { |
1291 | | - fail("hashes should not close AddInput"); |
1292 | | - } |
1293 | | - }); |
1294 | | - } finally { |
1295 | | - page.releaseBlocks(); |
1296 | | - } |
1297 | | - // TODO: randomize and try multiple pages. |
1298 | | - // TODO: assert the state of the BlockHash after adding pages. Including the categorizer state. |
1299 | | - // TODO: also test the lookup method and other stuff. |
1300 | | - } |
1301 | | - |
1302 | 1218 | record OrdsAndKeys(String description, int positionOffset, IntBlock ords, Block[] keys, IntVector nonEmpty) {} |
1303 | 1219 |
|
1304 | 1220 | /** |
@@ -1493,13 +1409,6 @@ private void assertKeys(Block[] actualKeys, Object[][] expectedKeys) { |
1493 | 1409 | } |
1494 | 1410 | } |
1495 | 1411 |
|
1496 | | - // A breaker service that always returns the given breaker for getBreaker(CircuitBreaker.REQUEST) |
1497 | | - static CircuitBreakerService mockBreakerService(CircuitBreaker breaker) { |
1498 | | - CircuitBreakerService breakerService = mock(CircuitBreakerService.class); |
1499 | | - when(breakerService.getBreaker(CircuitBreaker.REQUEST)).thenReturn(breaker); |
1500 | | - return breakerService; |
1501 | | - } |
1502 | | - |
1503 | 1412 | IntVector intRange(int startInclusive, int endExclusive) { |
1504 | 1413 | return IntVector.range(startInclusive, endExclusive, TestBlockFactory.getNonBreakingInstance()); |
1505 | 1414 | } |
|
0 commit comments