Skip to content

Commit

Permalink
updates/etc
Browse files Browse the repository at this point in the history
  • Loading branch information
kgyrtkirk committed Sep 19, 2023
1 parent 8e0989e commit 0be39d9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,34 @@

package org.apache.druid.sql.calcite;

import com.google.common.base.Throwables;
import org.apache.druid.error.DruidException;
import org.junit.AssumptionViolatedException;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.junit.Assert.assertThrows;

/**
* Can be used to mark tests which are not-yet supported in decoupled mode.
*
* In case a testcase marked with this annotation fails - it may mean that the
* testcase no longer needs that annotation.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface DecoupledIgnore
{
Modes mode() default Modes.NOT_ENOUGH_RULES;

enum Modes
{
PLAN_MISMATCH(AssertionError.class, "AssertionError: query #"),
Expand All @@ -56,6 +69,37 @@ Pattern getPattern()
}
};

Modes mode() default Modes.NOT_ENOUGH_RULES;

public static class DecoupledIgnoreProcessor implements TestRule
{
public Statement apply(Statement base, Description description)
{
DecoupledIgnore annotation = description.getAnnotation(DecoupledIgnore.class);
if (annotation == null) {
return base;
}
return new Statement()
{
@Override
public void evaluate() throws Throwable
{
Throwable e = assertThrows(
"Expected that this testcase will fail - it might got fixed?",
annotation.mode().throwableClass,
base::evaluate
);

String trace = Throwables.getStackTraceAsString(e);
Matcher m = annotation.mode().getPattern().matcher(trace);

if (!m.find()) {
throw new AssertionError("Exception stactrace doesn't match regex: " + annotation.mode().regex, e);
}
throw new AssumptionViolatedException("Test is not-yet supported in Decoupled mode");
}
};
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,20 @@

package org.apache.druid.sql.calcite;

import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMap;
import org.apache.druid.query.QueryContexts;
import org.apache.druid.server.security.AuthConfig;
import org.apache.druid.sql.calcite.DecoupledIgnore.DecoupledIgnoreProcessor;
import org.apache.druid.sql.calcite.planner.PlannerConfig;
import org.apache.druid.sql.calcite.util.SqlTestFramework;
import org.junit.AssumptionViolatedException;
import org.junit.Rule;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import java.util.regex.Matcher;

import static org.junit.Assert.assertThrows;

public class DecoupledPlanningCalciteQueryTest extends CalciteQueryTest
{

@Rule(order = 0)
public DecoupledIgnoreProcessor decoupledIgnoreProcessor = new DecoupledIgnoreProcessor();

public static class DecoupledIgnoreProcessor implements TestRule
{
public Statement apply(Statement base, Description description)
{
DecoupledIgnore annotation = description.getAnnotation(DecoupledIgnore.class);
if (annotation == null) {
return base;
}
return new Statement()
{
@Override
public void evaluate() throws Throwable
{
Throwable e = assertThrows(
"Expected that this testcase will fail - it might got fixed?",
annotation.mode().throwableClass,
base::evaluate
);

String trace = Throwables.getStackTraceAsString(e);
Matcher m = annotation.mode().getPattern().matcher(trace);

if (!m.find()) {
throw new AssertionError("Exception stactrace doesn't match regex: " + annotation.mode().regex, e);
}
throw new AssumptionViolatedException("Test is not-yet supported in Decoupled mode");
}
};
}
}

private static final ImmutableMap<String, Object> CONTEXT_OVERRIDES = ImmutableMap.of(
PlannerConfig.CTX_NATIVE_QUERY_SQL_PLANNING_MODE, PlannerConfig.NATIVE_QUERY_SQL_PLANNING_MODE_DECOUPLED,
QueryContexts.ENABLE_DEBUG, true);
Expand Down

0 comments on commit 0be39d9

Please sign in to comment.