Add PMD coverage for test sources. Reviewed at https://reviews.apache.org/r/41413/
Project: http://git-wip-us.apache.org/repos/asf/aurora/repo Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/fb8155d0 Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/fb8155d0 Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/fb8155d0 Branch: refs/heads/master Commit: fb8155d058b4258344e66b03ad1f1c730820fbb3 Parents: fe9b460 Author: Bill Farner <[email protected]> Authored: Tue Dec 15 16:04:44 2015 -0800 Committer: Bill Farner <[email protected]> Committed: Tue Dec 15 16:04:44 2015 -0800 ---------------------------------------------------------------------- build.gradle | 25 +-- config/pmd/common.xml | 70 ++++++++ config/pmd/custom.xml | 146 ---------------- config/pmd/main.xml | 109 ++++++++++++ config/pmd/test.xml | 81 +++++++++ .../scheduler/storage/log/LogStorage.java | 2 +- .../aurora/scheduler/app/SchedulerIT.java | 12 +- .../aurora/scheduler/app/local/FakeMaster.java | 14 +- .../scheduler/app/local/simulator/Events.java | 38 ----- .../app/local/simulator/FakeSlaves.java | 4 +- .../local/simulator/events/OfferAccepted.java | 32 ++++ .../app/local/simulator/events/Started.java | 20 +++ .../aurora/scheduler/async/AsyncModuleTest.java | 4 +- .../aurora/scheduler/cron/CrontabEntryTest.java | 6 +- .../aurora/scheduler/cron/quartz/CronIT.java | 6 +- .../cron/quartz/CronJobManagerImplTest.java | 6 +- .../scheduler/http/AbstractJettyTest.java | 165 +++++++++++++++++++ .../scheduler/http/H2ConsoleModuleIT.java | 2 +- .../scheduler/http/JettyServerModuleTest.java | 165 ------------------- .../apache/aurora/scheduler/http/MnameTest.java | 2 +- .../scheduler/http/ServletFilterTest.java | 2 +- .../aurora/scheduler/http/api/ApiBetaTest.java | 4 +- .../apache/aurora/scheduler/http/api/ApiIT.java | 4 +- .../http/api/security/HttpSecurityIT.java | 4 +- .../http/api/security/ModuleParserTest.java | 2 +- .../ShiroKerberosAuthenticationFilterTest.java | 4 +- ...berosPermissiveAuthenticationFilterTest.java | 9 +- .../scheduler/mesos/MesosSchedulerImplTest.java | 42 +++-- .../mesos/SchedulerDriverServiceTest.java | 2 +- .../preemptor/PendingTaskProcessorTest.java | 5 +- .../preemptor/PreemptionVictimFilterTest.java | 21 ++- .../scheduler/preemptor/PreemptorImplTest.java | 3 +- .../scheduler/quota/QuotaManagerImplTest.java | 7 +- .../reconciliation/TaskReconcilerTest.java | 4 +- .../scheduler/sla/MetricCalculatorTest.java | 2 +- .../aurora/scheduler/sla/SlaAlgorithmTest.java | 42 ++--- .../scheduler/state/StateManagerImplTest.java | 4 +- .../scheduler/state/TaskStateMachineTest.java | 21 ++- .../scheduler/stats/SlotSizeCounterTest.java | 16 +- .../storage/AbstractTaskStoreTest.java | 6 +- .../storage/db/DbAttributeStoreTest.java | 3 +- .../scheduler/storage/db/DbStorageTest.java | 4 +- .../scheduler/storage/log/LogManagerTest.java | 8 +- .../scheduler/storage/log/LogStorageTest.java | 98 ++++++----- .../storage/log/WriteAheadStorageTest.java | 16 +- .../storage/testing/StorageEntityUtil.java | 55 ++++--- 46 files changed, 700 insertions(+), 597 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/build.gradle ---------------------------------------------------------------------- diff --git a/build.gradle b/build.gradle index a91370f..3bd4cfd 100644 --- a/build.gradle +++ b/build.gradle @@ -402,27 +402,16 @@ tasks.withType(FindBugs) { pmd { toolVersion = '5.4.1' - - sourceSets = [sourceSets.main] - // PMD rule set names match XML files stored in the PMD jar. For example, with 5.11 you can - // see all the rules included with: - // $ find ~/.gradle -name pmd-5.1.1.jar | xargs zipinfo -1 | egrep java/.*.xml | head -n 5 - // rulesets/java/clone.xml - // rulesets/java/basic.xml - // rulesets/java/strings.xml - // rulesets/java/sunsecure.xml - // rulesets/java/codesize.xml - // The format is straightforward: 'java-basic' refers to rulesets/java/basic.xml. - ruleSets = [ - 'java-braces', - 'java-junit', - 'java-typeresolution', - 'java-unnecessary', - 'java-unusedcode'] - ruleSetFiles = fileTree('config/pmd/') consoleOutput = true } +pmdMain { + ruleSetFiles = files('config/pmd/common.xml', 'config/pmd/main.xml') +} + +pmdTest { + ruleSetFiles = files('config/pmd/common.xml', 'config/pmd/test.xml') +} /** * There is a jshint target recommended in the README for gradle-js-plugin http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/config/pmd/common.xml ---------------------------------------------------------------------- diff --git a/config/pmd/common.xml b/config/pmd/common.xml new file mode 100644 index 0000000..d37ef44 --- /dev/null +++ b/config/pmd/common.xml @@ -0,0 +1,70 @@ +<?xml version="1.0"?> +<!-- +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this work except in compliance with the License. +You may obtain a copy of the License in the LICENSE file, or at: + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> + +<ruleset name="Aurora" + xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"> + + <description> + Aurora PMD ruleset for all sources. + </description> + + <rule ref="rulesets/java/basic.xml"/> + <rule ref="rulesets/java/braces.xml"/> + <rule ref="rulesets/java/unnecessary.xml"/> + <rule ref="rulesets/java/unusedcode.xml"/> + + <rule ref="rulesets/java/naming.xml"> + <!-- Requiring longer variable names can be cumbersome when applied globally. --> + <exclude name="ShortVariable"/> + <!-- Requiring shorter variable names can be cumbersome when applied globally. --> + <exclude name="LongVariable"/> + <!-- Short method names are useful on occasion, such as with factory methods: Rate.of(...). --> + <exclude name="ShortMethodName"/> + <!-- TODO(wfarner): Enable this if/when we have automatic transaction management, rather than + the classes in org.apache.aurora.scheduler.storage.Storage (e.g. Work). --> + <exclude name="AbstractNaming"/> + <!-- There are rare, but valid, cases where short class names are useful. --> + <exclude name="ShortClassName"/> + </rule> + + <rule ref="rulesets/java/empty.xml"> + <!-- Configured below --> + <exclude name="EmptyCatchBlock"/> + </rule> + + <rule ref="rulesets/java/empty.xml/EmptyCatchBlock"> + <properties> + <!-- Some APIs, like the Java Reflection API, use exceptions to indicate the absence of + a value and we legitimately want to ignore them. --> + <property name="allowCommentedBlocks" value="true"/> + </properties> + </rule> + + <rule ref="rulesets/java/imports.xml"> + <!-- We frequently use static imports for enum fields (making other code more concise), but + those trip this rule. --> + <exclude name="TooManyStaticImports"/> + </rule> + + <rule ref="rulesets/java/logging-java.xml"> + <!-- It's valid to inject the logger, and in some cases preferable. --> + <exclude name="LoggerIsNotStaticFinal"/> + <!-- In practice, we don't have high enough log volume for this rule to be useful. --> + <exclude name="GuardLogStatementJavaUtil"/> + <exclude name="MoreThanOneLogger"/> + </rule> +</ruleset> http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/config/pmd/custom.xml ---------------------------------------------------------------------- diff --git a/config/pmd/custom.xml b/config/pmd/custom.xml deleted file mode 100644 index 763051b..0000000 --- a/config/pmd/custom.xml +++ /dev/null @@ -1,146 +0,0 @@ -<?xml version="1.0"?> -<!-- -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this work except in compliance with the License. -You may obtain a copy of the License in the LICENSE file, or at: - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. ---> - -<ruleset name="Aurora" - xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"> - - <description> - Aurora PMD ruleset. - </description> - - <rule ref="rulesets/java/basic.xml"> - </rule> - <rule ref="rulesets/java/design.xml"> - <!-- This rule suffers from false positivies in cases where we are implementing a third-party - interface. --> - <exclude name="UseVarargs"/> - - <!-- We're not currently focusing on localization. --> - <exclude name="SimpleDateFormatNeedsLocale"/> - <exclude name="UseLocaleWithCaseConversions"/> - <!-- We deliberately use method-level synchronization for simplicity in many cases. --> - <exclude name="AvoidSynchronizedAtMethodLevel"/> - <!-- Empty methods in abstract classes can save implementers from boilerplate. --> - <exclude name="EmptyMethodInAbstractClassShouldBeAbstract"/> - <!-- We don't follow this practice, as we often prefer to keep like constants closest to where - they are used. --> - <exclude name="FieldDeclarationsShouldBeAtStartOfClass"/> - <!-- Unfortunately we have several large classes that trip this rule. - TODO(wfarner): Break apart god classes. --> - <exclude name="GodClass"/> - - <!-- Classes that are only meant to be managed by mybatis with reflection trip this rule. --> - <exclude name="MissingStaticMethodInNonInstantiatableClass"/> - </rule> - <rule ref="rulesets/java/empty.xml"> - <!-- Configured below --> - <exclude name="EmptyCatchBlock"/> - </rule> - <rule ref="rulesets/java/empty.xml/EmptyCatchBlock"> - <properties> - <!-- Some APIs, like the Java Reflection API, use exceptions to indicate the absence of - a value and we legitimately want to ignore them. --> - <property name="allowCommentedBlocks" value="true"/> - </properties> - </rule> - <rule ref="rulesets/java/imports.xml"> - <!-- We frequently use static imports for enum fields (making other code more concise), but - those trip this rule. --> - <exclude name="TooManyStaticImports"/> - </rule> - <rule ref="rulesets/java/logging-java.xml"> - <!-- It's valid to inject the logger, and in some cases preferable. --> - <exclude name="LoggerIsNotStaticFinal"/> - <!-- In practice, we don't have high enough log volume for this rule to be useful. --> - <exclude name="GuardLogStatementJavaUtil"/> - </rule> - <rule ref="rulesets/java/naming.xml"> - <!-- Requiring longer variable names can be cumbersome when applied globally. --> - <exclude name="ShortVariable"/> - <!-- Requiring shorter variable names can be cumbersome when applied globally. --> - <exclude name="LongVariable"/> - <!-- Short method names are useful on occasion, such as with factory methods: Rate.of(...). --> - <exclude name="ShortMethodName"/> - <!-- TODO(wfarner): Enable this if/when we have automatic transaction management, rather than - the classes in org.apache.aurora.scheduler.storage.Storage (e.g. Work). --> - <exclude name="AbstractNaming"/> - <!-- There are rare, but valid, cases where short class names are useful. --> - <exclude name="ShortClassName"/> - </rule> - - <!-- Custom rules --> - <rule name="TimedAnnotationNonOverridableMethod" - language="java" - class="net.sourceforge.pmd.lang.rule.XPathRule" - message="A method must be overridable to have the @Timed annotation."> - <description> - A method must be overridable (non-static, non-final, public, protected or package-private) - in order to be used with the @Timed annotation. See: https://github.com/google/guice/wiki/AOP. - </description> - <priority>1</priority> - <properties> - <property name="xpath"> - <value> - <![CDATA[ -//ClassOrInterfaceBodyDeclaration[MethodDeclaration] -[count(./Annotation//Name[@Image='Timed']) > 0] -[count(./MethodDeclaration[(@Static = 'true') or (@Final = 'true') or (@Private = 'true')]) > 0] - ]]> - </value> - </property> - </properties> - <example> - <![CDATA[ - public class Foo { - @Timed - // Must be non-static, non-final, public, protected or package-private. - protected Foo() { } - } - ]]> - </example> - </rule> - - <rule name="TimedAnnotationNonOverridableClass" - language="java" - class="net.sourceforge.pmd.lang.rule.XPathRule" - message="A class must be non-final, public or package-private to have methods with the @Timed annotation."> - <description> - A class must be non-final, public or package-private to have methods with the @Timed - annotation. See: https://github.com/google/guice/wiki/AOP. - </description> - <priority>1</priority> - <properties> - <property name="xpath"> - <value> - <![CDATA[ -//ClassOrInterfaceDeclaration[(@Final = 'true') or (@Private = 'true') or (@Protected = 'true')] -/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/Annotation//Name[@Image='Timed'] - ]]> - </value> - </property> - </properties> - <example> - <![CDATA[ - // Must be non-final, public or package-private - class Foo { - @Timed - public Foo() { } - } - ]]> - </example> - </rule> -</ruleset> http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/config/pmd/main.xml ---------------------------------------------------------------------- diff --git a/config/pmd/main.xml b/config/pmd/main.xml new file mode 100644 index 0000000..b90c221 --- /dev/null +++ b/config/pmd/main.xml @@ -0,0 +1,109 @@ +<?xml version="1.0"?> +<!-- +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this work except in compliance with the License. +You may obtain a copy of the License in the LICENSE file, or at: + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> + +<ruleset name="Aurora" + xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"> + + <description> + Aurora PMD ruleset. + </description> + + <rule ref="rulesets/java/design.xml"> + <!-- This rule suffers from false positivies in cases where we are implementing a third-party + interface. --> + <exclude name="UseVarargs"/> + + <!-- We're not currently focusing on localization. --> + <exclude name="SimpleDateFormatNeedsLocale"/> + <exclude name="UseLocaleWithCaseConversions"/> + <!-- We deliberately use method-level synchronization for simplicity in many cases. --> + <exclude name="AvoidSynchronizedAtMethodLevel"/> + <!-- Empty methods in abstract classes can save implementers from boilerplate. --> + <exclude name="EmptyMethodInAbstractClassShouldBeAbstract"/> + <!-- We don't follow this practice, as we often prefer to keep like constants closest to where + they are used. --> + <exclude name="FieldDeclarationsShouldBeAtStartOfClass"/> + <!-- Unfortunately we have several large classes that trip this rule. + TODO(wfarner): Break apart god classes. --> + <exclude name="GodClass"/> + + <!-- Classes that are only meant to be managed by mybatis with reflection trip this rule. --> + <exclude name="MissingStaticMethodInNonInstantiatableClass"/> + </rule> + + <!-- Custom rules --> + <rule name="TimedAnnotationNonOverridableMethod" + language="java" + class="net.sourceforge.pmd.lang.rule.XPathRule" + message="A method must be overridable to have the @Timed annotation."> + <description> + A method must be overridable (non-static, non-final, public, protected or package-private) + in order to be used with the @Timed annotation. See: https://github.com/google/guice/wiki/AOP. + </description> + <priority>1</priority> + <properties> + <property name="xpath"> + <value> + <![CDATA[ +//ClassOrInterfaceBodyDeclaration[MethodDeclaration] +[count(./Annotation//Name[@Image='Timed']) > 0] +[count(./MethodDeclaration[(@Static = 'true') or (@Final = 'true') or (@Private = 'true')]) > 0] + ]]> + </value> + </property> + </properties> + <example> + <![CDATA[ + public class Foo { + @Timed + // Must be non-static, non-final, public, protected or package-private. + protected Foo() { } + } + ]]> + </example> + </rule> + + <rule name="TimedAnnotationNonOverridableClass" + language="java" + class="net.sourceforge.pmd.lang.rule.XPathRule" + message="A class must be non-final, public or package-private to have methods with the @Timed annotation."> + <description> + A class must be non-final, public or package-private to have methods with the @Timed + annotation. See: https://github.com/google/guice/wiki/AOP. + </description> + <priority>1</priority> + <properties> + <property name="xpath"> + <value> + <![CDATA[ +//ClassOrInterfaceDeclaration[(@Final = 'true') or (@Private = 'true') or (@Protected = 'true')] +/ClassOrInterfaceBody/ClassOrInterfaceBodyDeclaration/Annotation//Name[@Image='Timed'] + ]]> + </value> + </property> + </properties> + <example> + <![CDATA[ + // Must be non-final, public or package-private + class Foo { + @Timed + public Foo() { } + } + ]]> + </example> + </rule> +</ruleset> http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/config/pmd/test.xml ---------------------------------------------------------------------- diff --git a/config/pmd/test.xml b/config/pmd/test.xml new file mode 100644 index 0000000..4e4d196 --- /dev/null +++ b/config/pmd/test.xml @@ -0,0 +1,81 @@ +<?xml version="1.0"?> +<!-- +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this work except in compliance with the License. +You may obtain a copy of the License in the LICENSE file, or at: + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> + +<ruleset name="Aurora" + xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 http://pmd.sourceforge.net/ruleset_2_0_0.xsd"> + + <description> + Aurora PMD ruleset. + </description> + + <rule ref="rulesets/java/junit.xml"> + <!-- With the source code in hand, assertion messages can be redundant. --> + <exclude name="JUnitAssertionsShouldIncludeMessage"/> + + <!-- We have several cases where numerous assertions are valuable. --> + <exclude name="JUnitTestContainsTooManyAsserts"/> + + <!-- This rule seems to have false positives when the test uses helper methods for asserts. --> + <exclude name="JUnitTestsShouldIncludeAssert"/> + + <!-- Suffers from false positives for tests whose test cases are all defined in an abstract + super class. --> + <exclude name="TestClassWithoutTestCases"/> + </rule> + + <rule ref="rulesets/java/typeresolution.xml"> + <!-- We frequently use 'throws Exception' in test cases for convenience. --> + <exclude name="SignatureDeclareThrowsException"/> + </rule> + + <rule ref="rulesets/java/design.xml"> + <!-- This can trip for guice-bound classes using a package-private constructor. + --> + <exclude name="UseUtilityClass"/> + + <!-- This rule suffers from false positivies in cases where we are implementing a third-party + interface. --> + <exclude name="UseVarargs"/> + + <!-- In tests we often instantiate private utility classes, which this rule does not like. --> + <exclude name="AccessorClassGeneration"/> + + <!-- We're not currently focusing on localization. --> + <exclude name="SimpleDateFormatNeedsLocale"/> + <exclude name="UseLocaleWithCaseConversions"/> + + <!-- Empty methods in abstract classes can save implementers from boilerplate. --> + <exclude name="EmptyMethodInAbstractClassShouldBeAbstract"/> + <!-- We don't follow this practice, as we often prefer to keep like constants closest to where + they are used. --> + <exclude name="FieldDeclarationsShouldBeAtStartOfClass"/> + + <exclude name="GodClass"/> + </rule> + + <rule ref="rulesets/java/naming.xml"> + <!-- Requiring longer variable names can be cumbersome when applied globally. --> + <exclude name="ShortVariable"/> + <!-- Requiring shorter variable names can be cumbersome when applied globally. --> + <exclude name="LongVariable"/> + <!-- Short method names are useful on occasion, such as with factory methods: Rate.of(...). --> + <exclude name="ShortMethodName"/> + + <!-- There are rare, but valid, cases where short class names are useful. --> + <exclude name="ShortClassName"/> + </rule> +</ruleset> http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/main/java/org/apache/aurora/scheduler/storage/log/LogStorage.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/aurora/scheduler/storage/log/LogStorage.java b/src/main/java/org/apache/aurora/scheduler/storage/log/LogStorage.java index 3a6d3e4..6928cc8 100644 --- a/src/main/java/org/apache/aurora/scheduler/storage/log/LogStorage.java +++ b/src/main/java/org/apache/aurora/scheduler/storage/log/LogStorage.java @@ -410,7 +410,7 @@ public class LogStorage implements NonVolatileStorage, DistributedSnapshotStore @Override public synchronized void start(final MutateWork.NoResult.Quiet initializationLogic) { - write((NoResult.Quiet) (MutableStoreProvider unused) -> { + write((NoResult.Quiet) unused -> { // Must have the underlying storage started so we can query it for the last checkpoint. // We replay these entries in the forwarded storage system's transactions but not ours - we // do not want to re-record these ops to the log. http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/app/SchedulerIT.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/app/SchedulerIT.java b/src/test/java/org/apache/aurora/scheduler/app/SchedulerIT.java index 73f74ea..35a4d62 100644 --- a/src/test/java/org/apache/aurora/scheduler/app/SchedulerIT.java +++ b/src/test/java/org/apache/aurora/scheduler/app/SchedulerIT.java @@ -126,13 +126,12 @@ public class SchedulerIT extends BaseZooKeeperTest { .setName("test framework") .build()); - private ExecutorService executor = Executors.newCachedThreadPool( + private final ExecutorService executor = Executors.newCachedThreadPool( new ThreadFactoryBuilder().setNameFormat("SchedulerIT-%d").setDaemon(true).build()); - private AtomicReference<Optional<RuntimeException>> mainException = + private final AtomicReference<Optional<RuntimeException>> mainException = Atomics.newReference(Optional.absent()); private IMocksControl control; - private Injector injector; private SchedulerDriver driver; private DriverFactory driverFactory; @@ -142,7 +141,6 @@ public class SchedulerIT extends BaseZooKeeperTest { private EntrySerializer entrySerializer; private ZooKeeperClient zkClient; private File backupDir; - private Lifecycle lifecycle; @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); @@ -204,7 +202,7 @@ public class SchedulerIT extends BaseZooKeeperTest { .create(ImmutableList.of(InetSocketAddress.createUnresolved("localhost", getPort()))) .withCredentials(credentials); SchedulerMain main = SchedulerMain.class.newInstance(); - injector = Guice.createInjector( + Injector injector = Guice.createInjector( ImmutableList.<Module>builder() .add(SchedulerMain.getUniversalModule()) .add(new LogStorageModule()) @@ -214,7 +212,7 @@ public class SchedulerIT extends BaseZooKeeperTest { .build() ); injector.injectMembers(main); - lifecycle = injector.getInstance(Lifecycle.class); + Lifecycle lifecycle = injector.getInstance(Lifecycle.class); executor.submit(() -> { try { @@ -248,7 +246,7 @@ public class SchedulerIT extends BaseZooKeeperTest { }).get(); } - private AtomicInteger curPosition = new AtomicInteger(); + private final AtomicInteger curPosition = new AtomicInteger(); private static class IntPosition implements Position { private final int pos; http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/app/local/FakeMaster.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/app/local/FakeMaster.java b/src/test/java/org/apache/aurora/scheduler/app/local/FakeMaster.java index 73ea3cb..e551755 100644 --- a/src/test/java/org/apache/aurora/scheduler/app/local/FakeMaster.java +++ b/src/test/java/org/apache/aurora/scheduler/app/local/FakeMaster.java @@ -35,7 +35,7 @@ import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.SettableFuture; -import org.apache.aurora.scheduler.app.local.simulator.Events.Started; +import org.apache.aurora.scheduler.app.local.simulator.events.Started; import org.apache.aurora.scheduler.mesos.DriverFactory; import org.apache.mesos.Protos; import org.apache.mesos.Protos.ExecutorID; @@ -137,7 +137,7 @@ public class FakeMaster implements SchedulerDriver, DriverFactory { if (allOffers.isEmpty()) { LOG.info("All offers consumed, suppressing offer cycle."); } else { - Futures.getUnchecked(schedulerFuture).resourceOffers(FakeMaster.this, allOffers); + Futures.getUnchecked(schedulerFuture).resourceOffers(this, allOffers); } }, 1, @@ -224,7 +224,7 @@ public class FakeMaster implements SchedulerDriver, DriverFactory { executor.schedule( () -> Futures.getUnchecked(schedulerFuture).statusUpdate( - FakeMaster.this, + this, TaskStatus.newBuilder() .setTaskId(task.getTaskId()) .setState(TaskState.TASK_RUNNING) @@ -306,11 +306,11 @@ public class FakeMaster implements SchedulerDriver, DriverFactory { private static final class Task { private final Offer offer; - private final TaskInfo task; + private final TaskInfo taskInfo; - private Task(Offer offer, TaskInfo task) { + private Task(Offer offer, TaskInfo taskInfo) { this.offer = offer; - this.task = task; + this.taskInfo = taskInfo; } Offer getOffer() { @@ -318,7 +318,7 @@ public class FakeMaster implements SchedulerDriver, DriverFactory { } TaskInfo getTask() { - return task; + return taskInfo; } } } http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/app/local/simulator/Events.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/app/local/simulator/Events.java b/src/test/java/org/apache/aurora/scheduler/app/local/simulator/Events.java deleted file mode 100644 index f36c1ff..0000000 --- a/src/test/java/org/apache/aurora/scheduler/app/local/simulator/Events.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.aurora.scheduler.app.local.simulator; - -import org.apache.mesos.Protos.OfferID; -import org.apache.mesos.Protos.TaskInfo; - -import static java.util.Objects.requireNonNull; - -/** - * Pubsub events used to signal fake cluster activity. - */ -public interface Events { - - class Started { - } - - class OfferAccepted { - public final OfferID offer; - public final TaskInfo task; - - public OfferAccepted(OfferID offer, TaskInfo task) { - this.offer = requireNonNull(offer); - this.task = requireNonNull(task); - } - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/app/local/simulator/FakeSlaves.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/app/local/simulator/FakeSlaves.java b/src/test/java/org/apache/aurora/scheduler/app/local/simulator/FakeSlaves.java index 9274e7b..d8724e4 100644 --- a/src/test/java/org/apache/aurora/scheduler/app/local/simulator/FakeSlaves.java +++ b/src/test/java/org/apache/aurora/scheduler/app/local/simulator/FakeSlaves.java @@ -24,8 +24,8 @@ import com.google.common.eventbus.Subscribe; import com.google.common.util.concurrent.ThreadFactoryBuilder; import org.apache.aurora.scheduler.app.local.FakeMaster; -import org.apache.aurora.scheduler.app.local.simulator.Events.OfferAccepted; -import org.apache.aurora.scheduler.app.local.simulator.Events.Started; +import org.apache.aurora.scheduler.app.local.simulator.events.OfferAccepted; +import org.apache.aurora.scheduler.app.local.simulator.events.Started; import org.apache.mesos.Protos.Offer; import org.apache.mesos.Protos.TaskState; http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/app/local/simulator/events/OfferAccepted.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/app/local/simulator/events/OfferAccepted.java b/src/test/java/org/apache/aurora/scheduler/app/local/simulator/events/OfferAccepted.java new file mode 100644 index 0000000..2fd9c5e --- /dev/null +++ b/src/test/java/org/apache/aurora/scheduler/app/local/simulator/events/OfferAccepted.java @@ -0,0 +1,32 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.aurora.scheduler.app.local.simulator.events; + +import org.apache.mesos.Protos.OfferID; +import org.apache.mesos.Protos.TaskInfo; + +import static java.util.Objects.requireNonNull; + +/** + * Event indicating that an offer has been accepted. + */ +public class OfferAccepted { + public final OfferID offer; + public final TaskInfo task; + + public OfferAccepted(OfferID offer, TaskInfo task) { + this.offer = requireNonNull(offer); + this.task = requireNonNull(task); + } +} http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/app/local/simulator/events/Started.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/app/local/simulator/events/Started.java b/src/test/java/org/apache/aurora/scheduler/app/local/simulator/events/Started.java new file mode 100644 index 0000000..706fd25 --- /dev/null +++ b/src/test/java/org/apache/aurora/scheduler/app/local/simulator/events/Started.java @@ -0,0 +1,20 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.aurora.scheduler.app.local.simulator.events; + +/** + * Event indicating that the driver has started. + */ +public class Started { +} http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/async/AsyncModuleTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/async/AsyncModuleTest.java b/src/test/java/org/apache/aurora/scheduler/async/AsyncModuleTest.java index 259ed86..4c263f9 100644 --- a/src/test/java/org/apache/aurora/scheduler/async/AsyncModuleTest.java +++ b/src/test/java/org/apache/aurora/scheduler/async/AsyncModuleTest.java @@ -45,13 +45,11 @@ import static org.junit.Assert.assertEquals; public class AsyncModuleTest extends EasyMockTest { private FakeStatsProvider statsProvider; - private StorageTestUtil storageUtil; @Before public void setUp() { statsProvider = new FakeStatsProvider(); - storageUtil = new StorageTestUtil(this); - storageUtil.expectOperations(); + new StorageTestUtil(this).expectOperations(); } private Injector createInjector(Module module) { http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/cron/CrontabEntryTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/cron/CrontabEntryTest.java b/src/test/java/org/apache/aurora/scheduler/cron/CrontabEntryTest.java index 57e0241..7c7a950 100644 --- a/src/test/java/org/apache/aurora/scheduler/cron/CrontabEntryTest.java +++ b/src/test/java/org/apache/aurora/scheduler/cron/CrontabEntryTest.java @@ -14,10 +14,9 @@ package org.apache.aurora.scheduler.cron; import java.util.List; -import java.util.Set; import com.google.common.collect.ImmutableList; -import com.google.common.collect.Sets; +import com.google.common.collect.ImmutableSet; import org.junit.Test; @@ -43,8 +42,7 @@ public class CrontabEntryTest { } } - Set<CrontabEntry> equivalentEntries = Sets.newHashSet(entries); - assertTrue(equivalentEntries.size() == 1); + assertEquals(1, ImmutableSet.copyOf(entries).size()); } @Test http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/cron/quartz/CronIT.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/cron/quartz/CronIT.java b/src/test/java/org/apache/aurora/scheduler/cron/quartz/CronIT.java index 9cca71b..17d12c3 100644 --- a/src/test/java/org/apache/aurora/scheduler/cron/quartz/CronIT.java +++ b/src/test/java/org/apache/aurora/scheduler/cron/quartz/CronIT.java @@ -49,6 +49,7 @@ import org.quartz.TriggerListener; import static org.easymock.EasyMock.expectLastCall; import static org.easymock.EasyMock.isA; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; public class CronIT extends EasyMockTest { @@ -116,7 +117,7 @@ public class CronIT extends EasyMockTest { control.replay(); Scheduler scheduler = injector.getInstance(Scheduler.class); - assertTrue(!scheduler.isStarted()); + assertFalse(scheduler.isStarted()); Service cronLifecycle = boot(); @@ -125,7 +126,7 @@ public class CronIT extends EasyMockTest { cronLifecycle.stopAsync().awaitTerminated(); - assertTrue(!cronLifecycle.isRunning()); + assertFalse(cronLifecycle.isRunning()); assertTrue(scheduler.isShutdown()); } @@ -199,6 +200,7 @@ public class CronIT extends EasyMockTest { @Override public void triggerFired(Trigger trigger, JobExecutionContext context) { + // No-op. } @Override http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/cron/quartz/CronJobManagerImplTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/cron/quartz/CronJobManagerImplTest.java b/src/test/java/org/apache/aurora/scheduler/cron/quartz/CronJobManagerImplTest.java index ce6426b..716e0a1 100644 --- a/src/test/java/org/apache/aurora/scheduler/cron/quartz/CronJobManagerImplTest.java +++ b/src/test/java/org/apache/aurora/scheduler/cron/quartz/CronJobManagerImplTest.java @@ -208,7 +208,7 @@ public class CronJobManagerImplTest extends EasyMockTest { @Test public void testGetScheduledJobs() throws Exception { CronTrigger cronTrigger = createMock(CronTrigger.class); - expect(scheduler.getJobKeys(EasyMock.anyObject())) + expect(scheduler.getJobKeys(anyObject())) .andReturn(ImmutableSet.of(QuartzTestUtil.QUARTZ_JOB_KEY)); EasyMock. <List<? extends Trigger>>expect(scheduler.getTriggersOfJob(QuartzTestUtil.QUARTZ_JOB_KEY)) @@ -223,7 +223,7 @@ public class CronJobManagerImplTest extends EasyMockTest { @Test public void testGetScheduledJobsEmpty() throws Exception { - expect(scheduler.getJobKeys(EasyMock.anyObject())) + expect(scheduler.getJobKeys(anyObject())) .andReturn(ImmutableSet.of(QuartzTestUtil.QUARTZ_JOB_KEY)); EasyMock. <List<? extends Trigger>>expect(scheduler.getTriggersOfJob(QuartzTestUtil.QUARTZ_JOB_KEY)) @@ -235,7 +235,7 @@ public class CronJobManagerImplTest extends EasyMockTest { @Test(expected = RuntimeException.class) public void testGetScheduledJobsFails() throws Exception { - expect(scheduler.getJobKeys(EasyMock.anyObject())) + expect(scheduler.getJobKeys(anyObject())) .andReturn(ImmutableSet.of(QuartzTestUtil.QUARTZ_JOB_KEY)); EasyMock. <List<? extends Trigger>>expect(scheduler.getTriggersOfJob(QuartzTestUtil.QUARTZ_JOB_KEY)) http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/http/AbstractJettyTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/http/AbstractJettyTest.java b/src/test/java/org/apache/aurora/scheduler/http/AbstractJettyTest.java new file mode 100644 index 0000000..5768481 --- /dev/null +++ b/src/test/java/org/apache/aurora/scheduler/http/AbstractJettyTest.java @@ -0,0 +1,165 @@ +/** + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.aurora.scheduler.http; + +import javax.servlet.ServletContextListener; +import javax.ws.rs.core.MediaType; + +import com.google.common.base.Throwables; +import com.google.common.net.HostAndPort; +import com.google.common.util.concurrent.RateLimiter; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.Module; +import com.google.inject.TypeLiteral; +import com.google.inject.util.Modules; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.api.client.config.ClientConfig; +import com.sun.jersey.api.client.config.DefaultClientConfig; +import com.sun.jersey.api.json.JSONConfiguration; + +import org.apache.aurora.GuavaUtils.ServiceManagerIface; +import org.apache.aurora.common.base.Command; +import org.apache.aurora.common.net.pool.DynamicHostSet; +import org.apache.aurora.common.net.pool.DynamicHostSet.HostChangeMonitor; +import org.apache.aurora.common.quantity.Amount; +import org.apache.aurora.common.quantity.Time; +import org.apache.aurora.common.stats.StatsProvider; +import org.apache.aurora.common.testing.easymock.EasyMockTest; +import org.apache.aurora.common.thrift.ServiceInstance; +import org.apache.aurora.common.util.BackoffStrategy; +import org.apache.aurora.gen.ServerInfo; +import org.apache.aurora.scheduler.AppStartup; +import org.apache.aurora.scheduler.SchedulerServicesModule; +import org.apache.aurora.scheduler.app.LifecycleModule; +import org.apache.aurora.scheduler.async.AsyncModule; +import org.apache.aurora.scheduler.cron.CronJobManager; +import org.apache.aurora.scheduler.http.api.GsonMessageBodyHandler; +import org.apache.aurora.scheduler.offers.OfferManager; +import org.apache.aurora.scheduler.scheduling.RescheduleCalculator; +import org.apache.aurora.scheduler.scheduling.TaskGroups.TaskGroupsSettings; +import org.apache.aurora.scheduler.scheduling.TaskScheduler; +import org.apache.aurora.scheduler.state.LockManager; +import org.apache.aurora.scheduler.stats.StatsModule; +import org.apache.aurora.scheduler.storage.Storage; +import org.apache.aurora.scheduler.storage.entities.IServerInfo; +import org.apache.aurora.scheduler.storage.testing.StorageTestUtil; +import org.apache.aurora.scheduler.testing.FakeStatsProvider; +import org.easymock.Capture; +import org.junit.Before; + +import static org.apache.aurora.scheduler.http.JettyServerModule.makeServletContextListener; +import static org.easymock.EasyMock.capture; +import static org.easymock.EasyMock.expect; +import static org.junit.Assert.assertNotNull; + +/** + * TODO(wfarner): Break apart ServletModule so test setup isn't so involved. + * TODO(wfarner): Come up with an approach for these tests that doesn't require starting an actual + * HTTP server for each test case. + * + */ +public abstract class AbstractJettyTest extends EasyMockTest { + private Injector injector; + protected StorageTestUtil storage; + protected HostAndPort httpServer; + protected Capture<HostChangeMonitor<ServiceInstance>> schedulerWatcher; + + /** + * Subclasses should override with a module that configures the servlets they are testing. + * + * @return A module used in the creation of the servlet container's child injector. + */ + protected Module getChildServletModule() { + return Modules.EMPTY_MODULE; + } + + @Before + public void setUpBase() throws Exception { + storage = new StorageTestUtil(this); + final DynamicHostSet<ServiceInstance> schedulers = + createMock(new Clazz<DynamicHostSet<ServiceInstance>>() { }); + + injector = Guice.createInjector( + new StatsModule(), + new LifecycleModule(), + new SchedulerServicesModule(), + new AsyncModule(), + new AbstractModule() { + <T> T bindMock(Class<T> clazz) { + T mock = createMock(clazz); + bind(clazz).toInstance(mock); + return mock; + } + + @Override + protected void configure() { + bind(StatsProvider.class).toInstance(new FakeStatsProvider()); + bind(Storage.class).toInstance(storage.storage); + bind(IServerInfo.class).toInstance(IServerInfo.build(new ServerInfo() + .setClusterName("unittest") + .setThriftAPIVersion(100) + .setStatsUrlPrefix("none"))); + bind(TaskGroupsSettings.class).toInstance( + new TaskGroupsSettings( + Amount.of(1L, Time.MILLISECONDS), + bindMock(BackoffStrategy.class), + RateLimiter.create(1000))); + bind(new TypeLiteral<DynamicHostSet<ServiceInstance>>() { }).toInstance(schedulers); + bindMock(CronJobManager.class); + bindMock(LockManager.class); + bindMock(OfferManager.class); + bindMock(RescheduleCalculator.class); + bindMock(TaskScheduler.class); + bindMock(Thread.UncaughtExceptionHandler.class); + + bind(ServletContextListener.class).toProvider(() -> { + return makeServletContextListener(injector, getChildServletModule()); + }); + } + }, + new JettyServerModule(false)); + schedulerWatcher = createCapture(); + expect(schedulers.watch(capture(schedulerWatcher))).andReturn(createMock(Command.class)); + } + + protected void replayAndStart() { + control.replay(); + try { + injector.getInstance(Key.get(ServiceManagerIface.class, AppStartup.class)) + .startAsync().awaitHealthy(); + } catch (Exception e) { + throw Throwables.propagate(e); + } + httpServer = injector.getInstance(HttpService.class).getAddress(); + } + + protected String makeUrl(String path) { + return String.format("http://%s:%s%s", httpServer.getHostText(), httpServer.getPort(), path); + } + + protected WebResource.Builder getRequestBuilder(String path) { + assertNotNull("HTTP server must be started first", httpServer); + ClientConfig config = new DefaultClientConfig(); + config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); + config.getClasses().add(GsonMessageBodyHandler.class); + Client client = Client.create(config); + // Disable redirects so we can unit test them. + client.setFollowRedirects(false); + return client.resource(makeUrl(path)).getRequestBuilder().accept(MediaType.APPLICATION_JSON); + } +} http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/http/H2ConsoleModuleIT.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/http/H2ConsoleModuleIT.java b/src/test/java/org/apache/aurora/scheduler/http/H2ConsoleModuleIT.java index 6ffb370..b8a419c 100644 --- a/src/test/java/org/apache/aurora/scheduler/http/H2ConsoleModuleIT.java +++ b/src/test/java/org/apache/aurora/scheduler/http/H2ConsoleModuleIT.java @@ -23,7 +23,7 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; -public class H2ConsoleModuleIT extends JettyServerModuleTest { +public class H2ConsoleModuleIT extends AbstractJettyTest { @Override protected Module getChildServletModule() { return new H2ConsoleModule(true); http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/http/JettyServerModuleTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/http/JettyServerModuleTest.java b/src/test/java/org/apache/aurora/scheduler/http/JettyServerModuleTest.java deleted file mode 100644 index abf823a..0000000 --- a/src/test/java/org/apache/aurora/scheduler/http/JettyServerModuleTest.java +++ /dev/null @@ -1,165 +0,0 @@ -/** - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.aurora.scheduler.http; - -import javax.servlet.ServletContextListener; -import javax.ws.rs.core.MediaType; - -import com.google.common.base.Throwables; -import com.google.common.net.HostAndPort; -import com.google.common.util.concurrent.RateLimiter; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.Module; -import com.google.inject.TypeLiteral; -import com.google.inject.util.Modules; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.config.ClientConfig; -import com.sun.jersey.api.client.config.DefaultClientConfig; -import com.sun.jersey.api.json.JSONConfiguration; - -import org.apache.aurora.GuavaUtils.ServiceManagerIface; -import org.apache.aurora.common.base.Command; -import org.apache.aurora.common.net.pool.DynamicHostSet; -import org.apache.aurora.common.net.pool.DynamicHostSet.HostChangeMonitor; -import org.apache.aurora.common.quantity.Amount; -import org.apache.aurora.common.quantity.Time; -import org.apache.aurora.common.stats.StatsProvider; -import org.apache.aurora.common.testing.easymock.EasyMockTest; -import org.apache.aurora.common.thrift.ServiceInstance; -import org.apache.aurora.common.util.BackoffStrategy; -import org.apache.aurora.gen.ServerInfo; -import org.apache.aurora.scheduler.AppStartup; -import org.apache.aurora.scheduler.SchedulerServicesModule; -import org.apache.aurora.scheduler.app.LifecycleModule; -import org.apache.aurora.scheduler.async.AsyncModule; -import org.apache.aurora.scheduler.cron.CronJobManager; -import org.apache.aurora.scheduler.http.api.GsonMessageBodyHandler; -import org.apache.aurora.scheduler.offers.OfferManager; -import org.apache.aurora.scheduler.scheduling.RescheduleCalculator; -import org.apache.aurora.scheduler.scheduling.TaskGroups.TaskGroupsSettings; -import org.apache.aurora.scheduler.scheduling.TaskScheduler; -import org.apache.aurora.scheduler.state.LockManager; -import org.apache.aurora.scheduler.stats.StatsModule; -import org.apache.aurora.scheduler.storage.Storage; -import org.apache.aurora.scheduler.storage.entities.IServerInfo; -import org.apache.aurora.scheduler.storage.testing.StorageTestUtil; -import org.apache.aurora.scheduler.testing.FakeStatsProvider; -import org.easymock.Capture; -import org.junit.Before; - -import static org.apache.aurora.scheduler.http.JettyServerModule.makeServletContextListener; -import static org.easymock.EasyMock.capture; -import static org.easymock.EasyMock.expect; -import static org.junit.Assert.assertNotNull; - -/** - * TODO(wfarner): Break apart ServletModule so test setup isn't so involved. - * TODO(wfarner): Come up with an approach for these tests that doesn't require starting an actual - * HTTP server for each test case. - * - */ -public abstract class JettyServerModuleTest extends EasyMockTest { - private Injector injector; - protected StorageTestUtil storage; - protected HostAndPort httpServer; - protected Capture<HostChangeMonitor<ServiceInstance>> schedulerWatcher; - - /** - * Subclasses should override with a module that configures the servlets they are testing. - * - * @return A module used in the creation of the servlet container's child injector. - */ - protected Module getChildServletModule() { - return Modules.EMPTY_MODULE; - } - - @Before - public void setUpBase() throws Exception { - storage = new StorageTestUtil(this); - final DynamicHostSet<ServiceInstance> schedulers = - createMock(new Clazz<DynamicHostSet<ServiceInstance>>() { }); - - injector = Guice.createInjector( - new StatsModule(), - new LifecycleModule(), - new SchedulerServicesModule(), - new AsyncModule(), - new AbstractModule() { - <T> T bindMock(Class<T> clazz) { - T mock = createMock(clazz); - bind(clazz).toInstance(mock); - return mock; - } - - @Override - protected void configure() { - bind(StatsProvider.class).toInstance(new FakeStatsProvider()); - bind(Storage.class).toInstance(storage.storage); - bind(IServerInfo.class).toInstance(IServerInfo.build(new ServerInfo() - .setClusterName("unittest") - .setThriftAPIVersion(100) - .setStatsUrlPrefix("none"))); - bind(TaskGroupsSettings.class).toInstance( - new TaskGroupsSettings( - Amount.of(1L, Time.MILLISECONDS), - bindMock(BackoffStrategy.class), - RateLimiter.create(1000))); - bind(new TypeLiteral<DynamicHostSet<ServiceInstance>>() { }).toInstance(schedulers); - bindMock(CronJobManager.class); - bindMock(LockManager.class); - bindMock(OfferManager.class); - bindMock(RescheduleCalculator.class); - bindMock(TaskScheduler.class); - bindMock(Thread.UncaughtExceptionHandler.class); - - bind(ServletContextListener.class).toProvider(() -> { - return makeServletContextListener(injector, getChildServletModule()); - }); - } - }, - new JettyServerModule(false)); - schedulerWatcher = createCapture(); - expect(schedulers.watch(capture(schedulerWatcher))).andReturn(createMock(Command.class)); - } - - protected void replayAndStart() { - control.replay(); - try { - injector.getInstance(Key.get(ServiceManagerIface.class, AppStartup.class)) - .startAsync().awaitHealthy(); - } catch (Exception e) { - throw Throwables.propagate(e); - } - httpServer = injector.getInstance(HttpService.class).getAddress(); - } - - protected String makeUrl(String path) { - return String.format("http://%s:%s%s", httpServer.getHostText(), httpServer.getPort(), path); - } - - protected WebResource.Builder getRequestBuilder(String path) { - assertNotNull("HTTP server must be started first", httpServer); - ClientConfig config = new DefaultClientConfig(); - config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); - config.getClasses().add(GsonMessageBodyHandler.class); - Client client = Client.create(config); - // Disable redirects so we can unit test them. - client.setFollowRedirects(false); - return client.resource(makeUrl(path)).getRequestBuilder().accept(MediaType.APPLICATION_JSON); - } -} http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/http/MnameTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/http/MnameTest.java b/src/test/java/org/apache/aurora/scheduler/http/MnameTest.java index 8f76230..c25264f 100644 --- a/src/test/java/org/apache/aurora/scheduler/http/MnameTest.java +++ b/src/test/java/org/apache/aurora/scheduler/http/MnameTest.java @@ -36,7 +36,7 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; -public class MnameTest extends JettyServerModuleTest { +public class MnameTest extends AbstractJettyTest { private static final String SLAVE_HOST = "fakehost"; private static final int PORT = 50000; http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/http/ServletFilterTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/http/ServletFilterTest.java b/src/test/java/org/apache/aurora/scheduler/http/ServletFilterTest.java index d0c4449..af1e5f1 100644 --- a/src/test/java/org/apache/aurora/scheduler/http/ServletFilterTest.java +++ b/src/test/java/org/apache/aurora/scheduler/http/ServletFilterTest.java @@ -28,7 +28,7 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; -public class ServletFilterTest extends JettyServerModuleTest { +public class ServletFilterTest extends AbstractJettyTest { protected ClientResponse get(String path) { return getRequestBuilder(path) http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/http/api/ApiBetaTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/http/api/ApiBetaTest.java b/src/test/java/org/apache/aurora/scheduler/http/api/ApiBetaTest.java index 6dc65b5..2b5a82d 100644 --- a/src/test/java/org/apache/aurora/scheduler/http/api/ApiBetaTest.java +++ b/src/test/java/org/apache/aurora/scheduler/http/api/ApiBetaTest.java @@ -48,7 +48,7 @@ import org.apache.aurora.gen.ScheduledTask; import org.apache.aurora.gen.TaskConfig; import org.apache.aurora.gen.TaskConstraint; import org.apache.aurora.gen.TaskQuery; -import org.apache.aurora.scheduler.http.JettyServerModuleTest; +import org.apache.aurora.scheduler.http.AbstractJettyTest; import org.apache.aurora.scheduler.storage.entities.IJobConfiguration; import org.apache.aurora.scheduler.storage.entities.IResponse; import org.apache.aurora.scheduler.storage.entities.ITaskConfig; @@ -63,7 +63,7 @@ import static org.easymock.EasyMock.eq; import static org.easymock.EasyMock.expect; import static org.junit.Assert.assertEquals; -public class ApiBetaTest extends JettyServerModuleTest { +public class ApiBetaTest extends AbstractJettyTest { private AnnotatedAuroraAdmin thrift; @Before http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/http/api/ApiIT.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/http/api/ApiIT.java b/src/test/java/org/apache/aurora/scheduler/http/api/ApiIT.java index aa3a85a..31f5cb3 100644 --- a/src/test/java/org/apache/aurora/scheduler/http/api/ApiIT.java +++ b/src/test/java/org/apache/aurora/scheduler/http/api/ApiIT.java @@ -21,7 +21,7 @@ import com.google.inject.util.Modules; import com.sun.jersey.api.client.ClientResponse; import org.apache.aurora.gen.Response; -import org.apache.aurora.scheduler.http.JettyServerModuleTest; +import org.apache.aurora.scheduler.http.AbstractJettyTest; import org.apache.aurora.scheduler.thrift.aop.AnnotatedAuroraAdmin; import org.junit.Before; import org.junit.Test; @@ -29,7 +29,7 @@ import org.junit.Test; import static org.easymock.EasyMock.expect; import static org.junit.Assert.assertEquals; -public class ApiIT extends JettyServerModuleTest { +public class ApiIT extends AbstractJettyTest { private AnnotatedAuroraAdmin thrift; @Before http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/http/api/security/HttpSecurityIT.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/http/api/security/HttpSecurityIT.java b/src/test/java/org/apache/aurora/scheduler/http/api/security/HttpSecurityIT.java index 23db909..ac92117 100644 --- a/src/test/java/org/apache/aurora/scheduler/http/api/security/HttpSecurityIT.java +++ b/src/test/java/org/apache/aurora/scheduler/http/api/security/HttpSecurityIT.java @@ -31,8 +31,8 @@ import org.apache.aurora.gen.ResponseCode; import org.apache.aurora.gen.TaskQuery; import org.apache.aurora.scheduler.base.JobKeys; import org.apache.aurora.scheduler.base.Query; +import org.apache.aurora.scheduler.http.AbstractJettyTest; import org.apache.aurora.scheduler.http.H2ConsoleModule; -import org.apache.aurora.scheduler.http.JettyServerModuleTest; import org.apache.aurora.scheduler.http.api.ApiModule; import org.apache.aurora.scheduler.storage.entities.IJobKey; import org.apache.aurora.scheduler.thrift.aop.AnnotatedAuroraAdmin; @@ -63,7 +63,7 @@ import static org.easymock.EasyMock.expect; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; -public class HttpSecurityIT extends JettyServerModuleTest { +public class HttpSecurityIT extends AbstractJettyTest { private static final Response OK = new Response().setResponseCode(ResponseCode.OK); private static final UsernamePasswordCredentials ROOT = http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/http/api/security/ModuleParserTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/http/api/security/ModuleParserTest.java b/src/test/java/org/apache/aurora/scheduler/http/api/security/ModuleParserTest.java index 42eec12..baaeb23 100644 --- a/src/test/java/org/apache/aurora/scheduler/http/api/security/ModuleParserTest.java +++ b/src/test/java/org/apache/aurora/scheduler/http/api/security/ModuleParserTest.java @@ -31,7 +31,7 @@ public class ModuleParserTest { } static class NoNullaryConstructorModule implements Module { - private String name; + private final String name; NoNullaryConstructorModule(String name) { this.name = name; http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/http/api/security/ShiroKerberosAuthenticationFilterTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/http/api/security/ShiroKerberosAuthenticationFilterTest.java b/src/test/java/org/apache/aurora/scheduler/http/api/security/ShiroKerberosAuthenticationFilterTest.java index f35dcb8..20e3d62 100644 --- a/src/test/java/org/apache/aurora/scheduler/http/api/security/ShiroKerberosAuthenticationFilterTest.java +++ b/src/test/java/org/apache/aurora/scheduler/http/api/security/ShiroKerberosAuthenticationFilterTest.java @@ -26,7 +26,7 @@ import com.google.inject.servlet.ServletModule; import com.google.inject.util.Providers; import com.sun.jersey.api.client.ClientResponse; -import org.apache.aurora.scheduler.http.JettyServerModuleTest; +import org.apache.aurora.scheduler.http.AbstractJettyTest; import org.apache.shiro.authc.AuthenticationException; import org.apache.shiro.authc.AuthenticationToken; import org.apache.shiro.subject.Subject; @@ -38,7 +38,7 @@ import static org.easymock.EasyMock.expectLastCall; import static org.easymock.EasyMock.isA; import static org.junit.Assert.assertEquals; -public class ShiroKerberosAuthenticationFilterTest extends JettyServerModuleTest { +public class ShiroKerberosAuthenticationFilterTest extends AbstractJettyTest { private static final String PATH = "/test"; private Subject subject; http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/http/api/security/ShiroKerberosPermissiveAuthenticationFilterTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/http/api/security/ShiroKerberosPermissiveAuthenticationFilterTest.java b/src/test/java/org/apache/aurora/scheduler/http/api/security/ShiroKerberosPermissiveAuthenticationFilterTest.java index 6eb82b5..0018467 100644 --- a/src/test/java/org/apache/aurora/scheduler/http/api/security/ShiroKerberosPermissiveAuthenticationFilterTest.java +++ b/src/test/java/org/apache/aurora/scheduler/http/api/security/ShiroKerberosPermissiveAuthenticationFilterTest.java @@ -26,7 +26,7 @@ import com.google.inject.servlet.ServletModule; import com.google.inject.util.Providers; import com.sun.jersey.api.client.ClientResponse; -import org.apache.aurora.scheduler.http.JettyServerModuleTest; +import org.apache.aurora.scheduler.http.AbstractJettyTest; import org.apache.shiro.authz.UnauthenticatedException; import org.apache.shiro.subject.Subject; import org.junit.Before; @@ -36,20 +36,19 @@ import static org.easymock.EasyMock.anyObject; import static org.easymock.EasyMock.expectLastCall; import static org.junit.Assert.assertEquals; -public class ShiroKerberosPermissiveAuthenticationFilterTest extends JettyServerModuleTest { +public class ShiroKerberosPermissiveAuthenticationFilterTest extends AbstractJettyTest { private static final String PATH = "/test"; - private Subject subject; private HttpServlet mockServlet; private ShiroKerberosPermissiveAuthenticationFilter filter; @Before public void setUp() { - subject = createMock(Subject.class); mockServlet = createMock(HttpServlet.class); - filter = new ShiroKerberosPermissiveAuthenticationFilter(Providers.of(subject)); + filter = + new ShiroKerberosPermissiveAuthenticationFilter(Providers.of(createMock(Subject.class))); } @Override http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/mesos/MesosSchedulerImplTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/mesos/MesosSchedulerImplTest.java b/src/test/java/org/apache/aurora/scheduler/mesos/MesosSchedulerImplTest.java index ecef202..6dffd77 100644 --- a/src/test/java/org/apache/aurora/scheduler/mesos/MesosSchedulerImplTest.java +++ b/src/test/java/org/apache/aurora/scheduler/mesos/MesosSchedulerImplTest.java @@ -27,7 +27,6 @@ import org.apache.aurora.common.application.Lifecycle; import org.apache.aurora.common.base.Command; import org.apache.aurora.common.testing.easymock.EasyMockTest; import org.apache.aurora.gen.HostAttributes; -import org.apache.aurora.gen.MaintenanceMode; import org.apache.aurora.scheduler.HostOffer; import org.apache.aurora.scheduler.TaskStatusHandler; import org.apache.aurora.scheduler.base.Conversions; @@ -132,7 +131,6 @@ public class MesosSchedulerImplTest extends EasyMockTest { Optional.of(1000000L) ); - private Logger log; private StorageTestUtil storageUtil; private Command shutdownCommand; private TaskStatusHandler statusHandler; @@ -144,7 +142,7 @@ public class MesosSchedulerImplTest extends EasyMockTest { @Before public void setUp() { - log = Logger.getAnonymousLogger(); + Logger log = Logger.getAnonymousLogger(); log.setLevel(Level.INFO); initializeScheduler(log); } @@ -178,7 +176,7 @@ public class MesosSchedulerImplTest extends EasyMockTest { @Test public void testNoOffers() { - new RegisteredFixture() { + new AbstractRegisteredTest() { @Override void test() { scheduler.resourceOffers(driver, ImmutableList.of()); @@ -188,7 +186,7 @@ public class MesosSchedulerImplTest extends EasyMockTest { @Test public void testAcceptOffer() { - new OfferFixture() { + new AbstractOfferTest() { @Override void respondToOffer() { expectOfferAttributesSaved(OFFER); @@ -205,7 +203,7 @@ public class MesosSchedulerImplTest extends EasyMockTest { mockLogger.log(eq(Level.FINE), anyString()); initializeScheduler(mockLogger); - new OfferFixture() { + new AbstractOfferTest() { @Override void respondToOffer() { expectOfferAttributesSaved(OFFER); @@ -216,7 +214,7 @@ public class MesosSchedulerImplTest extends EasyMockTest { @Test public void testAttributesModePreserved() { - new OfferFixture() { + new AbstractOfferTest() { @Override void respondToOffer() { IHostAttributes draining = @@ -250,7 +248,7 @@ public class MesosSchedulerImplTest extends EasyMockTest { @Test(expected = SchedulerException.class) public void testStatusUpdateFails() { - new StatusFixture() { + new AbstractStatusTest() { @Override void expectations() { eventSink.post(new TaskStatusReceived( @@ -267,7 +265,7 @@ public class MesosSchedulerImplTest extends EasyMockTest { @Test public void testMultipleOffers() { - new RegisteredFixture() { + new AbstractRegisteredTest() { @Override void expectations() { expectOfferAttributesSaved(OFFER); @@ -285,7 +283,7 @@ public class MesosSchedulerImplTest extends EasyMockTest { @Test public void testDisconnected() { - new RegisteredFixture() { + new AbstractRegisteredTest() { @Override void expectations() { eventSink.post(new DriverDisconnected()); @@ -355,7 +353,7 @@ public class MesosSchedulerImplTest extends EasyMockTest { mockLogger.log(eq(Level.FINE), anyString()); initializeScheduler(mockLogger); - new StatusReconciliationFixture() { + new AbstractStatusReconciliationTest() { @Override void expectations() { eventSink.post(PUBSUB_RECONCILIATION_EVENT); @@ -364,7 +362,7 @@ public class MesosSchedulerImplTest extends EasyMockTest { }.run(); } - private class StatusUpdater extends StatusFixture { + private class StatusUpdater extends AbstractStatusTest { StatusUpdater(TaskStatus status) { super(status); } @@ -385,14 +383,14 @@ public class MesosSchedulerImplTest extends EasyMockTest { expect(storageUtil.attributeStore.getHostAttributes(offer.getOffer().getHostname())) .andReturn(Optional.absent()); IHostAttributes defaultMode = IHostAttributes.build( - Conversions.getAttributes(offer.getOffer()).newBuilder().setMode(MaintenanceMode.NONE)); + Conversions.getAttributes(offer.getOffer()).newBuilder().setMode(NONE)); expect(storageUtil.attributeStore.saveHostAttributes(defaultMode)).andReturn(true); } - private abstract class RegisteredFixture { + private abstract class AbstractRegisteredTest { private final AtomicBoolean runCalled = new AtomicBoolean(false); - RegisteredFixture() { + AbstractRegisteredTest() { // Prevent otherwise silent noop tests that forget to call run(). addTearDown(new TearDown() { @Override @@ -422,8 +420,8 @@ public class MesosSchedulerImplTest extends EasyMockTest { abstract void test(); } - private abstract class OfferFixture extends RegisteredFixture { - OfferFixture() { + private abstract class AbstractOfferTest extends AbstractRegisteredTest { + AbstractOfferTest() { super(); } @@ -440,14 +438,14 @@ public class MesosSchedulerImplTest extends EasyMockTest { } } - private abstract class StatusFixture extends RegisteredFixture { + private abstract class AbstractStatusTest extends AbstractRegisteredTest { protected final TaskStatus status; - StatusFixture() { + AbstractStatusTest() { this(STATUS); } - StatusFixture(TaskStatus status) { + AbstractStatusTest(TaskStatus status) { super(); this.status = status; } @@ -458,8 +456,8 @@ public class MesosSchedulerImplTest extends EasyMockTest { } } - private abstract class StatusReconciliationFixture extends StatusFixture { - StatusReconciliationFixture() { + private abstract class AbstractStatusReconciliationTest extends AbstractStatusTest { + AbstractStatusReconciliationTest() { super(STATUS_RECONCILIATION); } } http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/mesos/SchedulerDriverServiceTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/mesos/SchedulerDriverServiceTest.java b/src/test/java/org/apache/aurora/scheduler/mesos/SchedulerDriverServiceTest.java index 45a8a5d..35620a1 100644 --- a/src/test/java/org/apache/aurora/scheduler/mesos/SchedulerDriverServiceTest.java +++ b/src/test/java/org/apache/aurora/scheduler/mesos/SchedulerDriverServiceTest.java @@ -145,6 +145,6 @@ public class SchedulerDriverServiceTest extends EasyMockTest { builder.build(), SETTINGS.getMasterUri())) .andReturn(schedulerDriver); - expect(schedulerDriver.start()).andReturn(Protos.Status.DRIVER_RUNNING); + expect(schedulerDriver.start()).andReturn(DRIVER_RUNNING); } } http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/preemptor/PendingTaskProcessorTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/preemptor/PendingTaskProcessorTest.java b/src/test/java/org/apache/aurora/scheduler/preemptor/PendingTaskProcessorTest.java index 49002d0..d11ae58 100644 --- a/src/test/java/org/apache/aurora/scheduler/preemptor/PendingTaskProcessorTest.java +++ b/src/test/java/org/apache/aurora/scheduler/preemptor/PendingTaskProcessorTest.java @@ -46,7 +46,6 @@ import org.apache.aurora.scheduler.storage.entities.ITaskConfig; import org.apache.aurora.scheduler.storage.testing.StorageTestUtil; import org.apache.aurora.scheduler.testing.FakeStatsProvider; import org.apache.mesos.Protos; -import org.easymock.EasyMock; import org.junit.Before; import org.junit.Test; @@ -248,9 +247,9 @@ public class PendingTaskProcessorTest extends EasyMockTest { private void expectSlotSearch(ITaskConfig config, IScheduledTask... victims) { expect(preemptionVictimFilter.filterPreemptionVictims( eq(config), - EasyMock.anyObject(), + anyObject(), anyObject(AttributeAggregate.class), - EasyMock.anyObject(), + anyObject(), eq(storageUtil.storeProvider))); expectLastCall().andReturn( victims.length == 0 http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/preemptor/PreemptionVictimFilterTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/preemptor/PreemptionVictimFilterTest.java b/src/test/java/org/apache/aurora/scheduler/preemptor/PreemptionVictimFilterTest.java index fca4c81..ef20641 100644 --- a/src/test/java/org/apache/aurora/scheduler/preemptor/PreemptionVictimFilterTest.java +++ b/src/test/java/org/apache/aurora/scheduler/preemptor/PreemptionVictimFilterTest.java @@ -30,7 +30,6 @@ import org.apache.aurora.gen.Attribute; import org.apache.aurora.gen.Constraint; import org.apache.aurora.gen.HostAttributes; import org.apache.aurora.gen.JobKey; -import org.apache.aurora.gen.MaintenanceMode; import org.apache.aurora.gen.ScheduleStatus; import org.apache.aurora.gen.ScheduledTask; import org.apache.aurora.gen.TaskConfig; @@ -77,9 +76,9 @@ public class PreemptionVictimFilterTest extends EasyMockTest { private static final String TASK_ID_B = "task_b"; private static final String TASK_ID_C = "task_c"; private static final String TASK_ID_D = "task_d"; - private static final String HOST = "host"; - private static final String RACK = "rack"; - private static final String SLAVE_ID = HOST + "_id"; + private static final String HOST_A = "hostA"; + private static final String RACK_A = "rackA"; + private static final String SLAVE_ID = HOST_A + "_id"; private static final String RACK_ATTRIBUTE = "rack"; private static final String HOST_ATTRIBUTE = "host"; private static final String OFFER = "offer"; @@ -444,7 +443,7 @@ public class PreemptionVictimFilterTest extends EasyMockTest { a1.getAssignedTask().getTask().setNumCpus(1).setRamMb(512); assignToHost(a1); - expect(storageUtil.attributeStore.getHostAttributes(HOST)).andReturn(Optional.absent()); + expect(storageUtil.attributeStore.getHostAttributes(HOST_A)).andReturn(Optional.absent()); control.replay(); @@ -515,12 +514,12 @@ public class PreemptionVictimFilterTest extends EasyMockTest { builder.getIdBuilder().setValue(offerId); builder.getFrameworkIdBuilder().setValue("framework-id"); builder.getSlaveIdBuilder().setValue(SLAVE_ID); - builder.setHostname(HOST); + builder.setHostname(HOST_A); builder.addAllResources(resources); return Optional.of(new HostOffer( builder.build(), - IHostAttributes.build(new HostAttributes().setMode(MaintenanceMode.NONE)))); + IHostAttributes.build(new HostAttributes().setMode(NONE)))); } private IExpectationSetters<Set<SchedulingFilter.Veto>> expectFiltering() { @@ -580,7 +579,7 @@ public class PreemptionVictimFilterTest extends EasyMockTest { private void assignToHost(ScheduledTask task) { task.setStatus(RUNNING); addEvent(task, RUNNING); - task.getAssignedTask().setSlaveHost(HOST); + task.getAssignedTask().setSlaveHost(HOST_A); task.getAssignedTask().setSlaveId(SLAVE_ID); } @@ -595,10 +594,10 @@ public class PreemptionVictimFilterTest extends EasyMockTest { // Sets up a normal host, no dedicated hosts and no maintenance. private void setUpHost() { IHostAttributes hostAttrs = IHostAttributes.build( - new HostAttributes().setHost(HOST).setSlaveId(HOST + "_id") - .setMode(NONE).setAttributes(ImmutableSet.of(rack(RACK), host(RACK)))); + new HostAttributes().setHost(HOST_A).setSlaveId(HOST_A + "_id") + .setMode(NONE).setAttributes(ImmutableSet.of(rack(RACK_A), host(RACK_A)))); - expect(storageUtil.attributeStore.getHostAttributes(HOST)) + expect(storageUtil.attributeStore.getHostAttributes(HOST_A)) .andReturn(Optional.of(hostAttrs)).anyTimes(); } } http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/preemptor/PreemptorImplTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/preemptor/PreemptorImplTest.java b/src/test/java/org/apache/aurora/scheduler/preemptor/PreemptorImplTest.java index e9a3703..98048fa 100644 --- a/src/test/java/org/apache/aurora/scheduler/preemptor/PreemptorImplTest.java +++ b/src/test/java/org/apache/aurora/scheduler/preemptor/PreemptorImplTest.java @@ -41,7 +41,6 @@ import org.apache.aurora.scheduler.storage.entities.IScheduledTask; import org.apache.aurora.scheduler.storage.entities.ITaskConfig; import org.apache.aurora.scheduler.testing.FakeStatsProvider; import org.apache.mesos.Protos; -import org.easymock.EasyMock; import org.junit.Before; import org.junit.Test; @@ -155,7 +154,7 @@ public class PreemptorImplTest extends EasyMockTest { eq(Tasks.id(preempted)), eq(Optional.absent()), eq(ScheduleStatus.PREEMPTING), - EasyMock.anyObject())) + anyObject())) .andReturn(StateChangeResult.SUCCESS); } http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/quota/QuotaManagerImplTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/quota/QuotaManagerImplTest.java b/src/test/java/org/apache/aurora/scheduler/quota/QuotaManagerImplTest.java index e68fc1d..920e3e5 100644 --- a/src/test/java/org/apache/aurora/scheduler/quota/QuotaManagerImplTest.java +++ b/src/test/java/org/apache/aurora/scheduler/quota/QuotaManagerImplTest.java @@ -37,7 +37,6 @@ import org.apache.aurora.gen.ScheduledTask; import org.apache.aurora.gen.TaskConfig; import org.apache.aurora.gen.TaskConstraint; import org.apache.aurora.gen.ValueConstraint; -import org.apache.aurora.scheduler.ResourceAggregates; import org.apache.aurora.scheduler.base.JobKeys; import org.apache.aurora.scheduler.base.Query; import org.apache.aurora.scheduler.quota.QuotaManager.QuotaException; @@ -724,7 +723,7 @@ public class QuotaManagerImplTest extends EasyMockTest { expectNoTasks(); expectQuota(IResourceAggregate.build(new ResourceAggregate(1, 1, 1))); - storageUtil.quotaStore.saveQuota(ROLE, ResourceAggregates.EMPTY); + storageUtil.quotaStore.saveQuota(ROLE, EMPTY); control.replay(); quotaManager.saveQuota( @@ -902,8 +901,8 @@ public class QuotaManagerImplTest extends EasyMockTest { } private IExpectationSetters<?> expectNoJobUpdates() { - return expect(jobUpdateStore.fetchJobUpdateSummaries( - QuotaManagerImpl.updateQuery(ROLE))).andReturn(ImmutableList.of()); + return expect(jobUpdateStore.fetchJobUpdateSummaries(updateQuery(ROLE))) + .andReturn(ImmutableList.of()); } private IExpectationSetters<?> expectNoTasks() { http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/reconciliation/TaskReconcilerTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/reconciliation/TaskReconcilerTest.java b/src/test/java/org/apache/aurora/scheduler/reconciliation/TaskReconcilerTest.java index d1675c6..5b4b3ac 100644 --- a/src/test/java/org/apache/aurora/scheduler/reconciliation/TaskReconcilerTest.java +++ b/src/test/java/org/apache/aurora/scheduler/reconciliation/TaskReconcilerTest.java @@ -63,7 +63,6 @@ public class TaskReconcilerTest extends EasyMockTest { private StatsProvider statsProvider; private Driver driver; private ScheduledExecutorService executorService; - private FakeScheduledExecutor clock; private AtomicLong explicitRuns; private AtomicLong implicitRuns; @@ -81,7 +80,8 @@ public class TaskReconcilerTest extends EasyMockTest { public void testExecution() { expect(statsProvider.makeCounter(EXPLICIT_STAT_NAME)).andReturn(explicitRuns); expect(statsProvider.makeCounter(IMPLICIT_STAT_NAME)).andReturn(implicitRuns); - clock = FakeScheduledExecutor.scheduleAtFixedRateExecutor(executorService, 2, 5); + FakeScheduledExecutor clock = + FakeScheduledExecutor.scheduleAtFixedRateExecutor(executorService, 2, 5); IScheduledTask task = makeTask("id1", TaskTestUtil.makeConfig(TaskTestUtil.JOB)); storageUtil.expectOperations(); http://git-wip-us.apache.org/repos/asf/aurora/blob/fb8155d0/src/test/java/org/apache/aurora/scheduler/sla/MetricCalculatorTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/aurora/scheduler/sla/MetricCalculatorTest.java b/src/test/java/org/apache/aurora/scheduler/sla/MetricCalculatorTest.java index ecfa895..89162d1 100644 --- a/src/test/java/org/apache/aurora/scheduler/sla/MetricCalculatorTest.java +++ b/src/test/java/org/apache/aurora/scheduler/sla/MetricCalculatorTest.java @@ -64,7 +64,7 @@ public class MetricCalculatorTest extends EasyMockTest { .build(); @Test - public void runTest() { + public void testRun() { FakeClock clock = new FakeClock(); StatsProvider statsProvider = createMock(StatsProvider.class); StatsProvider untracked = createMock(StatsProvider.class);
