Skip to content

Commit

Permalink
update block factory tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisHegarty committed Sep 20, 2023
1 parent 42774a5 commit 199617e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 30 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.compute;

import org.elasticsearch.common.breaker.CircuitBreaker;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.util.MockBigArrays;
import org.elasticsearch.common.util.PageCacheRecycler;
import org.elasticsearch.compute.data.BlockFactoryParameters;
import org.elasticsearch.indices.breaker.CircuitBreakerService;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class TestBlockFactoryParameters implements BlockFactoryParameters {

final CircuitBreaker breaker;
final BigArrays bigArrays;

public TestBlockFactoryParameters() {
breaker = new CountingCircuitBreaker("ESQL-test-breaker");

var breakerService = mock(CircuitBreakerService.class);
when(breakerService.getBreaker(CircuitBreaker.REQUEST)).thenReturn(breaker);
bigArrays = new MockBigArrays(PageCacheRecycler.NON_RECYCLING_INSTANCE, breakerService);
}

@Override
public CircuitBreaker breaker() {
return breaker;
}

@Override
public BigArrays bigArrays() {
return bigArrays;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

package org.elasticsearch.compute.data;

import com.carrotsearch.randomizedtesting.annotations.Name;
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;

import org.apache.lucene.util.Accountable;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.breaker.CircuitBreaker;
Expand All @@ -23,6 +26,8 @@
import org.junit.Before;

import java.util.BitSet;
import java.util.List;
import java.util.function.Supplier;

import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
Expand All @@ -34,16 +39,32 @@
// @com.carrotsearch.randomizedtesting.annotations.Repeat(iterations = 1000)
public class BlockFactoryTests extends ESTestCase {

final CircuitBreaker breaker = new CountingCircuitBreaker("ESQL-test-breaker");
final BigArrays bigArrays = bigArrays();
final BlockFactory blockFactory = BlockFactory.getInstance(breaker, bigArrays);
final CircuitBreaker breaker;
final BigArrays bigArrays;
final BlockFactory blockFactory;

BigArrays bigArrays() {
static BigArrays bigArrays(CircuitBreaker breaker) {
var breakerService = mock(CircuitBreakerService.class);
when(breakerService.getBreaker(CircuitBreaker.REQUEST)).thenReturn(breaker);
return new MockBigArrays(PageCacheRecycler.NON_RECYCLING_INSTANCE, breakerService);
}

@ParametersFactory
public static List<Object[]> params() {
List<Supplier<BlockFactory>> l = List.of(() -> {
CircuitBreaker breaker = new CountingCircuitBreaker("ESQL-test-breaker");
BigArrays bigArrays = bigArrays(breaker);
return BlockFactory.getInstance(breaker, bigArrays);
}, BlockFactory::getGlobalInstance);
return l.stream().map(s -> new Object[] { s }).toList();
}

public BlockFactoryTests(@Name("blockFactorySupplier") Supplier<BlockFactory> blockFactorySupplier) {
this.blockFactory = blockFactorySupplier.get();
this.breaker = blockFactory.breaker();
this.bigArrays = blockFactory.bigArrays();
}

@Before
@After
public void checkBreaker() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# 2.0.
#

org.elasticsearch.compute.TestBlockFactoryParamaters
org.elasticsearch.compute.TestBlockFactoryParameters

0 comments on commit 199617e

Please sign in to comment.