Search in sources :

Example 1 with MemoryCircuitBreaker

use of org.elasticsearch.common.breaker.MemoryCircuitBreaker in project crate by crate.

the class RowAccountingWithEstimatorsTest method testCircuitBreakingWorks.

@Test
public void testCircuitBreakingWorks() throws Exception {
    RowAccountingWithEstimators rowAccounting = new RowAccountingWithEstimators(Collections.singletonList(DataTypes.INTEGER), ConcurrentRamAccounting.forCircuitBreaker("test", new MemoryCircuitBreaker(new ByteSizeValue(10, ByteSizeUnit.BYTES), 1.01, LogManager.getLogger(RowAccountingWithEstimatorsTest.class))));
    expectedException.expect(CircuitBreakingException.class);
    RowGenerator.range(0, 3).forEach(rowAccounting::accountForAndMaybeBreak);
}
Also used : MemoryCircuitBreaker(org.elasticsearch.common.breaker.MemoryCircuitBreaker) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) Test(org.junit.Test)

Example 2 with MemoryCircuitBreaker

use of org.elasticsearch.common.breaker.MemoryCircuitBreaker in project crate by crate.

the class SortingProjectorTest method testUsedMemoryIsAccountedFor.

@Test
public void testUsedMemoryIsAccountedFor() throws Exception {
    MemoryCircuitBreaker circuitBreaker = new MemoryCircuitBreaker(new ByteSizeValue(30, ByteSizeUnit.BYTES), 1, LogManager.getLogger(SortingProjectorTest.class));
    RowCellsAccountingWithEstimators rowAccounting = new RowCellsAccountingWithEstimators(List.of(DataTypes.LONG, DataTypes.BOOLEAN), ConcurrentRamAccounting.forCircuitBreaker("testContext", circuitBreaker), 0);
    Projector projector = createProjector(rowAccounting, 1, 0);
    consumer.accept(projector.apply(TestingBatchIterators.range(1, 11)), null);
    expectedException.expect(CircuitBreakingException.class);
    consumer.getResult();
}
Also used : Projector(io.crate.data.Projector) RowCellsAccountingWithEstimators(io.crate.breaker.RowCellsAccountingWithEstimators) MemoryCircuitBreaker(org.elasticsearch.common.breaker.MemoryCircuitBreaker) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) Test(org.junit.Test)

Example 3 with MemoryCircuitBreaker

use of org.elasticsearch.common.breaker.MemoryCircuitBreaker in project crate by crate.

the class SortingTopNProjectorTest method testUsedMemoryIsAccountedFor.

@Test
public void testUsedMemoryIsAccountedFor() throws Exception {
    MemoryCircuitBreaker circuitBreaker = new MemoryCircuitBreaker(new ByteSizeValue(30, ByteSizeUnit.BYTES), 1, LogManager.getLogger(SortingTopNProjectorTest.class));
    RowCellsAccountingWithEstimators rowAccounting = new RowCellsAccountingWithEstimators(List.of(DataTypes.LONG, DataTypes.BOOLEAN), ConcurrentRamAccounting.forCircuitBreaker("testContext", circuitBreaker), 0);
    Projector projector = getProjector(rowAccounting, 1, 100_000, TopN.NO_OFFSET, FIRST_CELL_ORDERING);
    consumer.accept(projector.apply(TestingBatchIterators.range(1, 11)), null);
    expectedException.expect(CircuitBreakingException.class);
    consumer.getResult();
}
Also used : Projector(io.crate.data.Projector) RowCellsAccountingWithEstimators(io.crate.breaker.RowCellsAccountingWithEstimators) MemoryCircuitBreaker(org.elasticsearch.common.breaker.MemoryCircuitBreaker) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) Test(org.junit.Test)

Example 4 with MemoryCircuitBreaker

use of org.elasticsearch.common.breaker.MemoryCircuitBreaker in project crate by crate.

the class RamAccountingPageIteratorTest method testCircuitBreaking.

@Test
public void testCircuitBreaking() throws Exception {
    PagingIterator<Integer, Row> pagingIterator = PagingIterator.create(2, true, null, () -> new RowAccountingWithEstimators(List.of(DataTypes.STRING, DataTypes.STRING, DataTypes.STRING), ConcurrentRamAccounting.forCircuitBreaker("test", new MemoryCircuitBreaker(new ByteSizeValue(197, ByteSizeUnit.BYTES), 1, LogManager.getLogger(RowAccountingWithEstimatorsTest.class)))));
    expectedException.expect(CircuitBreakingException.class);
    expectedException.expectMessage("Data too large, data for field [test] would be [288/288b], which is larger than the limit of [197/197b]");
    pagingIterator.merge(Arrays.asList(new KeyIterable<>(0, Collections.singletonList(TEST_ROWS[0])), new KeyIterable<>(1, Collections.singletonList(TEST_ROWS[1]))));
}
Also used : MemoryCircuitBreaker(org.elasticsearch.common.breaker.MemoryCircuitBreaker) RowAccountingWithEstimators(io.crate.breaker.RowAccountingWithEstimators) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) Row(io.crate.data.Row) Test(org.junit.Test) RowAccountingWithEstimatorsTest(io.crate.breaker.RowAccountingWithEstimatorsTest)

Example 5 with MemoryCircuitBreaker

use of org.elasticsearch.common.breaker.MemoryCircuitBreaker in project crate by crate.

the class NodeFetchResponseTest method testResponseCircuitBreaker.

@Test
public void testResponseCircuitBreaker() throws Exception {
    NodeFetchResponse orig = new NodeFetchResponse(fetched);
    BytesStreamOutput out = new BytesStreamOutput();
    orig.writeTo(out);
    StreamInput in = out.bytes().streamInput();
    expectedException.expect(CircuitBreakingException.class);
    new NodeFetchResponse(in, streamers, ConcurrentRamAccounting.forCircuitBreaker("test", new MemoryCircuitBreaker(new ByteSizeValue(2, ByteSizeUnit.BYTES), 1.0, LogManager.getLogger(NodeFetchResponseTest.class))));
}
Also used : MemoryCircuitBreaker(org.elasticsearch.common.breaker.MemoryCircuitBreaker) StreamInput(org.elasticsearch.common.io.stream.StreamInput) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) Test(org.junit.Test)

Aggregations

MemoryCircuitBreaker (org.elasticsearch.common.breaker.MemoryCircuitBreaker)7 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)7 Test (org.junit.Test)7 RowCellsAccountingWithEstimators (io.crate.breaker.RowCellsAccountingWithEstimators)2 Projector (io.crate.data.Projector)2 RowAccountingWithEstimators (io.crate.breaker.RowAccountingWithEstimators)1 RowAccountingWithEstimatorsTest (io.crate.breaker.RowAccountingWithEstimatorsTest)1 Row (io.crate.data.Row)1 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)1 StreamInput (org.elasticsearch.common.io.stream.StreamInput)1