Skip to content

Commit

Permalink
junit5
Browse files Browse the repository at this point in the history
  • Loading branch information
ssalinas committed Jul 16, 2019
1 parent 25115be commit 53003ed
Show file tree
Hide file tree
Showing 57 changed files with 1,735 additions and 1,552 deletions.
20 changes: 16 additions & 4 deletions SingularityClient/pom.xml
Expand Up @@ -87,14 +87,26 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<scope>test</scope>
</dependency>

Expand Down
Expand Up @@ -2,7 +2,7 @@

import java.util.Collections;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.google.inject.AbstractModule;
import com.google.inject.Guice;
Expand Down
Expand Up @@ -3,14 +3,13 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;
import static org.mockito.internal.verification.VerificationModeFactory.times;

import java.net.URI;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
Expand All @@ -34,7 +33,7 @@ public class SingularityClientTest {

private SingularityClient singularityClient;

@Before
@BeforeEach
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
singularityClient = buildClient();
Expand Down
22 changes: 18 additions & 4 deletions SingularityExecutor/pom.xml
Expand Up @@ -117,15 +117,29 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Expand Up @@ -11,7 +11,7 @@

import javax.validation.Validator;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.jknack.handlebars.Handlebars;
Expand Down
20 changes: 16 additions & 4 deletions SingularityS3Base/pom.xml
Expand Up @@ -91,14 +91,26 @@

<!-- Unit test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<scope>test</scope>
</dependency>

Expand Down
@@ -1,4 +1,4 @@
package com.hubspot.singularity.executor.config;
package com.hubspot.singularity.s3.base;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
Expand All @@ -13,30 +13,22 @@
import java.util.Arrays;
import java.util.List;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.LoggerFactory;

import com.google.common.base.Throwables;
import com.hubspot.singularity.runner.base.configuration.SingularityRunnerBaseConfiguration;
import com.hubspot.singularity.runner.base.sentry.SingularityRunnerExceptionNotifier;
import com.hubspot.singularity.s3.base.ArtifactManager;
import com.hubspot.singularity.s3.base.config.SingularityS3Configuration;

public class ArtifactManagerTest {

private ArtifactManager artifactManager;

@Rule
public TemporaryFolder cacheDir = new TemporaryFolder();
private File cacheDir = com.google.common.io.Files.createTempDir();

@Rule
public ExpectedException expectedException = ExpectedException.none();

@Before
@BeforeEach
public void setup() {
SingularityRunnerBaseConfiguration baseConfig = new SingularityRunnerBaseConfiguration();
SingularityS3Configuration s3Config = new SingularityS3Configuration();
Expand All @@ -57,13 +49,13 @@ public void itAbsorbsFileAlreadyExistsExceptionsWhenCopyingDuplicateFiles() {

assertThat(originalPath.toFile()).hasContent(String.join(System.lineSeparator(), lines));

Path copyPath = Paths.get(cacheDir.getRoot().toString() + "/copy.txt");
Path copyPath = Paths.get(cacheDir.toString() + "/copy.txt");
assertThat(copyPath).doesNotExist();
artifactManager.copy(originalPath, cacheDir.getRoot().toPath(), "copy.txt");
artifactManager.copy(originalPath, cacheDir.toPath(), "copy.txt");
assertThat(copyPath).exists();

// A redundant copy operation should not throw.
artifactManager.copy(originalPath, cacheDir.getRoot().toPath(), "copy.txt");
artifactManager.copy(originalPath, cacheDir.toPath(), "copy.txt");
}

@Test
Expand All @@ -82,7 +74,7 @@ public void itPropagatesFileAlreadyExistsExceptionsWhenCopyingNonDuplicateFiles(

public Path write(String fileName, List<String> lines) {
try {
File file = cacheDir.newFile(fileName);
File file = cacheDir.toPath().resolve(fileName).toFile();
Path path = file.toPath();
Files.write(path, lines, Charset.forName("UTF-8"));
return path;
Expand Down
29 changes: 23 additions & 6 deletions SingularityService/pom.xml
Expand Up @@ -46,6 +46,11 @@
<artifactId>aws-java-sdk-sns</artifactId>
</dependency>

<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
Expand Down Expand Up @@ -479,12 +484,6 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
Expand All @@ -497,6 +496,24 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Expand Up @@ -76,7 +76,6 @@
import com.hubspot.singularity.sentry.NotifyingExceptionMapper;
import com.hubspot.singularity.sentry.SingularityExceptionNotifier;
import com.hubspot.singularity.sentry.SingularityExceptionNotifierManaged;
import com.hubspot.singularity.smtp.JadeTemplateLoader;
import com.hubspot.singularity.smtp.MailTemplateHelpers;
import com.hubspot.singularity.smtp.NoopMailer;
import com.hubspot.singularity.smtp.SingularityMailRecordCleaner;
Expand All @@ -85,8 +84,8 @@
import com.hubspot.singularity.smtp.SmtpMailer;
import com.ning.http.client.AsyncHttpClient;

import de.neuland.jade4j.parser.Parser;
import de.neuland.jade4j.parser.node.Node;
import de.neuland.jade4j.JadeConfiguration;
import de.neuland.jade4j.template.ClasspathTemplateLoader;
import de.neuland.jade4j.template.JadeTemplate;
import io.dropwizard.jetty.ConnectorFactory;
import io.dropwizard.jetty.HttpConnectorFactory;
Expand Down Expand Up @@ -331,57 +330,51 @@ public HistoryPurgingConfiguration historyPurgingConfiguration(final Singularity
}

private JadeTemplate getJadeTemplate(String name) throws IOException {
Parser parser = new Parser("templates/" + name, JadeTemplateLoader.JADE_LOADER);
Node root = parser.parse();

final JadeTemplate jadeTemplate = new JadeTemplate();

jadeTemplate.setTemplateLoader(JadeTemplateLoader.JADE_LOADER);
jadeTemplate.setRootNode(root);

return jadeTemplate;
JadeConfiguration config = new JadeConfiguration();
config.setTemplateLoader(new ClasspathTemplateLoader());
return config.getTemplate("templates/" + name);
}

@Provides
@Singleton
@Named(TASK_TEMPLATE)
public JadeTemplate getTaskTemplate() throws IOException {
return getJadeTemplate("task.jade");
return getJadeTemplate("task");
}

@Provides
@Singleton
@Named(REQUEST_IN_COOLDOWN_TEMPLATE)
public JadeTemplate getRequestPausedTemplate() throws IOException {
return getJadeTemplate("request_in_cooldown.jade");
return getJadeTemplate("request_in_cooldown");
}

@Provides
@Singleton
@Named(REQUEST_MODIFIED_TEMPLATE)
public JadeTemplate getRequestModifiedTemplate() throws IOException {
return getJadeTemplate("request_modified.jade");
return getJadeTemplate("request_modified");
}

@Provides
@Singleton
@Named(RATE_LIMITED_TEMPLATE)
public JadeTemplate getRateLimitedTemplate() throws IOException {
return getJadeTemplate("rate_limited.jade");
return getJadeTemplate("rate_limited");
}

@Provides
@Singleton
@Named(DISASTERS_TEMPLATE)
public JadeTemplate getDisastersTemplate() throws IOException {
return getJadeTemplate("disaster.jade");
return getJadeTemplate("disaster");
}

@Provides
@Singleton
@Named(REPLACEMENT_TASKS_FAILING_TEMPLATE)
public JadeTemplate getReplacementTasksFailingTemplate() throws IOException {
return getJadeTemplate("replacement_tasks_failing.jade");
return getJadeTemplate("replacement_tasks_failing");
}

@Provides
Expand Down
Expand Up @@ -78,7 +78,9 @@ public void start() throws Exception {
leaderController.start(); // start the state poller
graphiteReporter.start();
executorIdGenerator.start();
leaderOnlyPollers.forEach(SingularityLeaderOnlyPoller::start);
if (startLeaderPollers()) {
leaderOnlyPollers.forEach(SingularityLeaderOnlyPoller::start);
}
} else {
LOG.info("Already started, will not call again");
}
Expand All @@ -87,7 +89,9 @@ public void start() throws Exception {
@Override
public void stop() throws Exception {
if (!stopped.getAndSet(true)) {
stopNewPolls(); // Marks a boolean that will short circuit new runs of any leader only pollers
if (startLeaderPollers()) {
stopNewPolls(); // Marks a boolean that will short circuit new runs of any leader only pollers
}
stopDirectoryFetcher(); // use http client, stop this before client
stopStatePollerAndMesosConnection(); // Marks the scheduler as stopped
stopHttpClients(); // Stops any additional async callbacks in healthcheck/new task check
Expand All @@ -100,6 +104,11 @@ public void stop() throws Exception {
}
}

// to override in unit testing
protected boolean startLeaderPollers() {
return true;
}

private void stopDirectoryFetcher() {
try {
LOG.info("Stopping directory fetcher");
Expand Down

0 comments on commit 53003ed

Please sign in to comment.