Skip to content

Commit

Permalink
JAVA-3069: Refactor duplicated tests with different requirements to u…
Browse files Browse the repository at this point in the history
…se @BackendRequirement (#1667)

Refactor @BackendRequirement test skipping logic into new rule, BackendRequirementRule.
  • Loading branch information
hhughes authored Aug 21, 2023
1 parent d94a8f0 commit fd446ce
Show file tree
Hide file tree
Showing 80 changed files with 577 additions and 361 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
import com.datastax.oss.driver.api.core.cql.Row;
import com.datastax.oss.driver.api.testinfra.DseRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.SessionUtils;
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap;
import com.tngtech.java.junit.dataprovider.DataProvider;
Expand All @@ -32,7 +33,10 @@
import org.junit.Test;
import org.junit.runner.RunWith;

@DseRequirement(min = "5.0", description = "Required for DseAuthenticator")
@BackendRequirement(
type = BackendType.DSE,
minInclusive = "5.0",
description = "Required for DseAuthenticator")
@RunWith(DataProviderRunner.class)
public class DseGssApiAuthProviderAlternateIT {
@ClassRule public static EmbeddedAdsRule ads = new EmbeddedAdsRule(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,19 @@
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.auth.AuthenticationException;
import com.datastax.oss.driver.api.core.cql.ResultSet;
import com.datastax.oss.driver.api.testinfra.DseRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap;
import java.util.List;
import java.util.Map;
import org.junit.Assume;
import org.junit.ClassRule;
import org.junit.Test;

@DseRequirement(min = "5.0", description = "Required for DseAuthenticator")
@BackendRequirement(
type = BackendType.DSE,
minInclusive = "5.0",
description = "Required for DseAuthenticator")
public class DseGssApiAuthProviderIT {

@ClassRule public static EmbeddedAdsRule ads = new EmbeddedAdsRule();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
import com.datastax.oss.driver.api.core.Version;
import com.datastax.oss.driver.api.core.auth.AuthenticationException;
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
import com.datastax.oss.driver.api.testinfra.DseRequirement;
import com.datastax.oss.driver.api.testinfra.ccm.CustomCcmRule;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.SessionUtils;
import com.datastax.oss.driver.internal.core.auth.PlainTextAuthProvider;
import com.datastax.oss.driver.shaded.guava.common.util.concurrent.Uninterruptibles;
Expand All @@ -35,7 +36,10 @@
import org.junit.ClassRule;
import org.junit.Test;

@DseRequirement(min = "5.0", description = "Required for DseAuthenticator")
@BackendRequirement(
type = BackendType.DSE,
minInclusive = "5.0",
description = "Required for DseAuthenticator")
public class DsePlainTextAuthProviderIT {

@ClassRule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import com.datastax.oss.driver.api.core.cql.ResultSet;
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.core.servererrors.UnauthorizedException;
import com.datastax.oss.driver.api.testinfra.DseRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.SessionUtils;
import com.datastax.oss.driver.internal.core.auth.PlainTextAuthProvider;
import java.util.List;
Expand All @@ -36,7 +37,10 @@
import org.junit.ClassRule;
import org.junit.Test;

@DseRequirement(min = "5.1", description = "Required for DseAuthenticator with proxy")
@BackendRequirement(
type = BackendType.DSE,
minInclusive = "5.1",
description = "Required for DseAuthenticator with proxy")
public class DseProxyAuthenticationIT {
private static String bobPrincipal;
private static String charliePrincipal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@
import com.datastax.dse.driver.api.core.config.DseDriverOption;
import com.datastax.dse.driver.internal.core.auth.DseGssApiAuthProvider;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.Version;
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
import com.datastax.oss.driver.api.testinfra.ccm.CcmBridge;
import com.datastax.oss.driver.api.testinfra.ccm.CustomCcmRule;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.requirement.VersionRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirementRule;
import com.datastax.oss.driver.api.testinfra.session.SessionUtils;
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap;
import java.io.File;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import org.junit.AssumptionViolatedException;
Expand Down Expand Up @@ -155,20 +151,15 @@ protected void before() {

@Override
public Statement apply(Statement base, Description description) {
BackendType backend = CcmBridge.DSE_ENABLEMENT ? BackendType.DSE : BackendType.CASSANDRA;
Version version = CcmBridge.VERSION;

Collection<VersionRequirement> requirements = VersionRequirement.fromAnnotations(description);

if (VersionRequirement.meetsAny(requirements, backend, version)) {
if (BackendRequirementRule.meetsDescriptionRequirements(description)) {
return super.apply(base, description);
} else {
// requirements not met, throw reasoning assumption to skip test
return new Statement() {
@Override
public void evaluate() {
throw new AssumptionViolatedException(
VersionRequirement.buildReasonString(requirements, backend, version));
BackendRequirementRule.buildReasonString(description));
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.core.cql.Statement;
import com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric;
import com.datastax.oss.driver.api.testinfra.DseRequirement;
import com.datastax.oss.driver.api.testinfra.ccm.CcmRule;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
import com.datastax.oss.driver.api.testinfra.session.SessionUtils;
import com.datastax.oss.driver.categories.ParallelizableTests;
Expand All @@ -58,8 +59,9 @@
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;

@DseRequirement(
min = "5.1.0",
@BackendRequirement(
type = BackendType.DSE,
minInclusive = "5.1.0",
description = "Continuous paging is only available from 5.1.0 onwards")
@Category(ParallelizableTests.class)
@RunWith(DataProviderRunner.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
import com.datastax.oss.driver.api.core.cql.ExecutionInfo;
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric;
import com.datastax.oss.driver.api.testinfra.DseRequirement;
import com.datastax.oss.driver.api.testinfra.ccm.CcmRule;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
import com.datastax.oss.driver.api.testinfra.session.SessionUtils;
import com.datastax.oss.driver.categories.ParallelizableTests;
Expand All @@ -47,8 +48,9 @@
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;

@DseRequirement(
min = "5.1.0",
@BackendRequirement(
type = BackendType.DSE,
minInclusive = "5.1.0",
description = "Continuous paging is only available from 5.1.0 onwards")
@Category(ParallelizableTests.class)
@RunWith(DataProviderRunner.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import com.datastax.oss.driver.api.core.cql.Row;
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.core.uuid.Uuids;
import com.datastax.oss.driver.api.testinfra.DseRequirement;
import com.datastax.oss.driver.api.testinfra.ccm.CcmRule;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
import java.util.List;
import java.util.UUID;
Expand All @@ -34,7 +35,7 @@
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;

@DseRequirement(min = "5.0")
@BackendRequirement(type = BackendType.DSE, minInclusive = "5.0")
public class LineStringIT extends GeometryIT<LineString> {

private static CcmRule ccm = CcmRule.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
package com.datastax.dse.driver.api.core.data.geometry;

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.testinfra.DseRequirement;
import com.datastax.oss.driver.api.testinfra.ccm.CcmRule;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
import org.assertj.core.util.Lists;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;

@DseRequirement(min = "5.0")
@BackendRequirement(type = BackendType.DSE, minInclusive = "5.0")
public class PointIT extends GeometryIT<Point> {

private static CcmRule ccm = CcmRule.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import com.datastax.oss.driver.api.core.cql.Row;
import com.datastax.oss.driver.api.core.cql.SimpleStatement;
import com.datastax.oss.driver.api.core.uuid.Uuids;
import com.datastax.oss.driver.api.testinfra.DseRequirement;
import com.datastax.oss.driver.api.testinfra.ccm.CcmRule;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
import java.util.UUID;
import org.assertj.core.util.Lists;
Expand All @@ -33,7 +34,7 @@
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;

@DseRequirement(min = "5.0")
@BackendRequirement(type = BackendType.DSE, minInclusive = "5.0")
public class PolygonIT extends GeometryIT<Polygon> {

private static CcmRule ccm = CcmRule.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
import com.datastax.oss.driver.api.core.data.TupleValue;
import com.datastax.oss.driver.api.core.data.UdtValue;
import com.datastax.oss.driver.api.core.servererrors.InvalidQueryException;
import com.datastax.oss.driver.api.testinfra.DseRequirement;
import com.datastax.oss.driver.api.testinfra.ccm.CcmRule;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
import com.datastax.oss.driver.api.testinfra.session.SessionUtils;
import com.datastax.oss.driver.categories.ParallelizableTests;
Expand All @@ -44,7 +45,7 @@
import org.junit.rules.TestRule;

@Category({ParallelizableTests.class})
@DseRequirement(min = "5.1")
@BackendRequirement(type = BackendType.DSE, minInclusive = "5.1")
public class DateRangeIT {

private static CcmRule ccmRule = CcmRule.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
package com.datastax.dse.driver.api.core.graph;

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.testinfra.DseRequirement;
import com.datastax.oss.driver.api.testinfra.ccm.CustomCcmRule;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
import com.datastax.oss.driver.shaded.guava.common.base.Joiner;
import com.datastax.oss.driver.shaded.guava.common.collect.Lists;
Expand All @@ -30,7 +31,10 @@
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;

@DseRequirement(min = "5.1", description = "DSE 5.1 required for graph geo indexing")
@BackendRequirement(
type = BackendType.DSE,
minInclusive = "5.1",
description = "DSE 5.1 required for graph geo indexing")
public class ClassicGraphGeoSearchIndexIT extends GraphGeoSearchIndexITBase {
private static final CustomCcmRule CCM_RULE =
CustomCcmRule.builder().withDseWorkloads("graph", "solr").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
package com.datastax.dse.driver.api.core.graph;

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.testinfra.DseRequirement;
import com.datastax.oss.driver.api.testinfra.ccm.CustomCcmRule;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
import com.datastax.oss.driver.shaded.guava.common.base.Joiner;
import com.datastax.oss.driver.shaded.guava.common.collect.Lists;
Expand All @@ -30,7 +31,10 @@
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;

@DseRequirement(min = "5.1", description = "DSE 5.1 required for graph geo indexing")
@BackendRequirement(
type = BackendType.DSE,
minInclusive = "5.1",
description = "DSE 5.1 required for graph geo indexing")
public class ClassicGraphTextSearchIndexIT extends GraphTextSearchIndexITBase {
private static final CustomCcmRule CCM_RULE =
CustomCcmRule.builder().withDseWorkloads("graph", "solr").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
package com.datastax.dse.driver.api.core.graph;

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.testinfra.DseRequirement;
import com.datastax.oss.driver.api.testinfra.ccm.CustomCcmRule;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
import com.datastax.oss.driver.shaded.guava.common.collect.Lists;
import java.util.Collection;
Expand All @@ -28,7 +29,10 @@
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;

@DseRequirement(min = "6.8.0", description = "DSE 6.8.0 required for Core graph support")
@BackendRequirement(
type = BackendType.DSE,
minInclusive = "6.8.0",
description = "DSE 6.8.0 required for Core graph support")
public class CoreGraphGeoSearchIndexIT extends GraphGeoSearchIndexITBase {

private static final CustomCcmRule CCM_RULE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
package com.datastax.dse.driver.api.core.graph;

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.testinfra.DseRequirement;
import com.datastax.oss.driver.api.testinfra.ccm.CustomCcmRule;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
import com.datastax.oss.driver.shaded.guava.common.collect.Lists;
import java.util.Collection;
Expand All @@ -28,7 +29,10 @@
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;

@DseRequirement(min = "6.8.0", description = "DSE 6.8.0 required for Core graph support")
@BackendRequirement(
type = BackendType.DSE,
minInclusive = "6.8.0",
description = "DSE 6.8.0 required for Core graph support")
public class CoreGraphTextSearchIndexIT extends GraphTextSearchIndexITBase {

private static final CustomCcmRule CCM_RULE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@

import com.datastax.dse.driver.api.core.graph.predicates.CqlCollection;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.testinfra.DseRequirement;
import com.datastax.oss.driver.api.testinfra.ccm.CustomCcmRule;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.CqlSessionRuleBuilder;
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList;
Expand All @@ -41,7 +42,10 @@
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;

@DseRequirement(min = "6.8", description = "DSE 6.8.0 required for collection predicates support")
@BackendRequirement(
type = BackendType.DSE,
minInclusive = "6.8",
description = "DSE 6.8.0 required for collection predicates support")
public class CqlCollectionIT {

private static final CustomCcmRule CCM_RULE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import com.datastax.oss.driver.api.core.Version;
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
import com.datastax.oss.driver.api.testinfra.DseRequirement;
import com.datastax.oss.driver.api.testinfra.ccm.CustomCcmRule;
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
import com.datastax.oss.driver.api.testinfra.session.SessionUtils;
import com.datastax.oss.driver.internal.core.auth.PlainTextAuthProvider;
import com.datastax.oss.driver.shaded.guava.common.util.concurrent.Uninterruptibles;
Expand All @@ -32,7 +33,10 @@
import org.junit.ClassRule;
import org.junit.Test;

@DseRequirement(min = "5.0.0", description = "DSE 5 required for Graph")
@BackendRequirement(
type = BackendType.DSE,
minInclusive = "5.0.0",
description = "DSE 5 required for Graph")
public class GraphAuthenticationIT {

@ClassRule
Expand Down
Loading

0 comments on commit fd446ce

Please sign in to comment.