Support using a fake node count for unit tests
Allowing the LocalQueryRunner to estimate costs using a fake node count
allows unit tests to consider network costs and different cluster
configurations.
@@ -289,6 +289,11 @@ public class LocalQueryRunner
}
public LocalQueryRunner(Session defaultSession, FeaturesConfig featuresConfig, NodeSpillConfig nodeSpillConfig, boolean withInitialTransaction, boolean alwaysRevokeMemory)
+ {
+ this(defaultSession, featuresConfig, nodeSpillConfig, withInitialTransaction, alwaysRevokeMemory, 1);
+ }
+
+ private LocalQueryRunner(Session defaultSession, FeaturesConfig featuresConfig, NodeSpillConfig nodeSpillConfig, boolean withInitialTransaction, boolean alwaysRevokeMemory, int nodeCountForStats)
{
requireNonNull(defaultSession, "defaultSession is null");
checkArgument(!defaultSession.getTransactionId().isPresent() || !withInitialTransaction, "Already in transaction");
@@ -333,8 +338,8 @@ public class LocalQueryRunner
this.statsCalculator = new SelectingStatsCalculator(
new CoefficientBasedStatsCalculator(metadata),
ServerMainModule.createNewStatsCalculator(metadata));
- this.costCalculator = new CostCalculatorUsingExchanges(this::getNodeCount);
- this.estimatedExchangesCostCalculator = new CostCalculatorWithEstimatedExchanges(costCalculator, this::getNodeCount);
+ this.costCalculator = new CostCalculatorUsingExchanges(() -> nodeCountForStats);
+ this.estimatedExchangesCostCalculator = new CostCalculatorWithEstimatedExchanges(costCalculator, () -> nodeCountForStats);
this.accessControl = new TestingAccessControlManager(transactionManager);
this.pageSourceManager = new PageSourceManager();
@@ -437,6 +442,11 @@ public class LocalQueryRunner
return new LocalQueryRunner(defaultSession, new FeaturesConfig(), new NodeSpillConfig(), true, false);
}
+ public static LocalQueryRunner queryRunnerWithFakeNodeCountForStats(Session defaultSession, int nodeCount)
+ {
+ return new LocalQueryRunner(defaultSession, new FeaturesConfig(), new NodeSpillConfig(), false, false, nodeCount);
+ }
+
@Override
public void close()
{
