Search in sources :

Example 1 with CircuitBreakingException

use of org.opensearch.common.breaker.CircuitBreakingException in project OpenSearch by opensearch-project.

the class LimitedCharSequenceTests method testCharAtAboveLimit.

public void testCharAtAboveLimit() {
    String str = "abc";
    String patternStr = "a.*bc";
    Pattern p = Pattern.compile(patternStr);
    final CharSequence seq = new LimitedCharSequence(str, p, 2);
    for (int i = 0; i < 6; i++) {
        seq.charAt(0);
    }
    CircuitBreakingException circuitBreakingException = expectThrows(CircuitBreakingException.class, () -> seq.charAt(0));
    assertEquals("[scripting] Regular expression considered too many characters, " + "pattern: [a.*bc], " + "limit factor: [2], " + "char limit: [6], " + "count: [7], " + "wrapped: [abc], " + "this limit can be changed by changed by the [script.painless.regex.limit-factor] setting", circuitBreakingException.getMessage());
    final CharSequence seqNullPattern = new LimitedCharSequence(str, null, 2);
    for (int i = 0; i < 6; i++) {
        seqNullPattern.charAt(0);
    }
    circuitBreakingException = expectThrows(CircuitBreakingException.class, () -> seqNullPattern.charAt(0));
    assertEquals("[scripting] Regular expression considered too many characters, " + "limit factor: [2], " + "char limit: [6], " + "count: [7], " + "wrapped: [abc], " + "this limit can be changed by changed by the [script.painless.regex.limit-factor] setting", circuitBreakingException.getMessage());
}
Also used : Pattern(java.util.regex.Pattern) CircuitBreakingException(org.opensearch.common.breaker.CircuitBreakingException)

Example 2 with CircuitBreakingException

use of org.opensearch.common.breaker.CircuitBreakingException in project OpenSearch by opensearch-project.

the class RegexLimitTests method testRegexInject_Ref_SplitAsStream.

public void testRegexInject_Ref_SplitAsStream() {
    String script = "Stream splitStream(Function func) { func.apply(" + SPLIT_CHAR_SEQUENCE + "); } " + "Pattern pattern = " + PATTERN + ";" + "splitStream(pattern::splitAsStream).toArray(String[]::new)";
    CircuitBreakingException cbe = expectScriptThrows(CircuitBreakingException.class, () -> exec(script));
    assertTrue(cbe.getMessage().contains(REGEX_CIRCUIT_MESSAGE));
}
Also used : CircuitBreakingException(org.opensearch.common.breaker.CircuitBreakingException)

Example 3 with CircuitBreakingException

use of org.opensearch.common.breaker.CircuitBreakingException in project OpenSearch by opensearch-project.

the class RegexLimitTests method testRegexInject_Split.

public void testRegexInject_Split() {
    String[] scripts = new String[] { PATTERN + ".split(" + SPLIT_CHAR_SEQUENCE + ")", "Pattern p = " + PATTERN + "; p.split(" + SPLIT_CHAR_SEQUENCE + ")" };
    for (String script : scripts) {
        CircuitBreakingException cbe = expectScriptThrows(CircuitBreakingException.class, () -> exec(script));
        assertTrue(cbe.getMessage().contains(REGEX_CIRCUIT_MESSAGE));
    }
}
Also used : CircuitBreakingException(org.opensearch.common.breaker.CircuitBreakingException)

Example 4 with CircuitBreakingException

use of org.opensearch.common.breaker.CircuitBreakingException in project OpenSearch by opensearch-project.

the class RegexLimitTests method testRegexInjectFindOperator.

public void testRegexInjectFindOperator() {
    String script = "if (" + CHAR_SEQUENCE + " =~ " + PATTERN + ") { return 100; } return 200";
    CircuitBreakingException cbe = expectScriptThrows(CircuitBreakingException.class, () -> exec(script));
    assertTrue(cbe.getMessage().contains(REGEX_CIRCUIT_MESSAGE));
}
Also used : CircuitBreakingException(org.opensearch.common.breaker.CircuitBreakingException)

Example 5 with CircuitBreakingException

use of org.opensearch.common.breaker.CircuitBreakingException in project OpenSearch by opensearch-project.

the class RegexLimitTests method testRegexInject_SplitAsStream.

public void testRegexInject_SplitAsStream() {
    String[] scripts = new String[] { PATTERN + ".splitAsStream(" + SPLIT_CHAR_SEQUENCE + ").toArray(String[]::new)", "Pattern p = " + PATTERN + "; p.splitAsStream(" + SPLIT_CHAR_SEQUENCE + ").toArray(String[]::new)" };
    for (String script : scripts) {
        CircuitBreakingException cbe = expectScriptThrows(CircuitBreakingException.class, () -> exec(script));
        assertTrue(cbe.getMessage().contains(REGEX_CIRCUIT_MESSAGE));
    }
}
Also used : CircuitBreakingException(org.opensearch.common.breaker.CircuitBreakingException)

Aggregations

CircuitBreakingException (org.opensearch.common.breaker.CircuitBreakingException)43 Settings (org.opensearch.common.settings.Settings)10 ClusterSettings (org.opensearch.common.settings.ClusterSettings)9 ArrayList (java.util.ArrayList)7 ChildMemoryCircuitBreaker (org.opensearch.common.breaker.ChildMemoryCircuitBreaker)7 CircuitBreaker (org.opensearch.common.breaker.CircuitBreaker)6 NoopCircuitBreaker (org.opensearch.common.breaker.NoopCircuitBreaker)6 ByteSizeValue (org.opensearch.common.unit.ByteSizeValue)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 CircuitBreakerService (org.opensearch.indices.breaker.CircuitBreakerService)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Client (org.opensearch.client.Client)3 ShardId (org.opensearch.index.shard.ShardId)3 IOException (java.io.IOException)2 Collections (java.util.Collections)2 List (java.util.List)2 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2