Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #41 from rouzwawi/master
Browse files Browse the repository at this point in the history
General clean up
  • Loading branch information
rouzwawi committed Nov 23, 2015
2 parents 893bf9e + 5a8b045 commit 672b7ba
Show file tree
Hide file tree
Showing 21 changed files with 39 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import com.spotify.apollo.Request;
import com.spotify.apollo.Response;

import java.io.Closeable;
import java.io.IOException;
import java.util.Optional;
import java.util.concurrent.CompletionStage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
import com.spotify.apollo.Client;
import com.spotify.apollo.Request;
import com.spotify.apollo.Response;
import com.spotify.apollo.environment.IncomingRequestAwareClient;

import java.io.IOException;
import java.util.Optional;
import java.util.concurrent.CompletionStage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.spotify.apollo.Request;
import com.spotify.apollo.Response;

import java.io.IOException;
import java.util.concurrent.CompletionStage;

import okio.ByteString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.spotify.apollo.Response;
import com.spotify.apollo.environment.IncomingRequestAwareClient;

import java.io.IOException;
import java.net.URI;
import java.util.Objects;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class RequestTracker implements Closeable {
.setNameFormat("apollo-request-reaper")
.build());

private final Set<TrackedOngoingRequest> outstanding = ConcurrentHashMap.newKeySet();
private final Set<OngoingRequest> outstanding = ConcurrentHashMap.newKeySet();

private final ScheduledFuture<?> future;

Expand All @@ -61,11 +61,11 @@ public RequestTracker() {
this.future = TRACKER_EXECUTOR.scheduleWithFixedDelay(this::reap, 10, 10, TimeUnit.MILLISECONDS);
}

public void register(TrackedOngoingRequest request) {
public void register(OngoingRequest request) {
outstanding.add(request);
}

public boolean remove(TrackedOngoingRequest request) {
public boolean remove(OngoingRequest request) {
return this.outstanding.remove(request);
}

Expand All @@ -85,7 +85,7 @@ public void close() {
void reap() {
outstanding.stream()
// Drop expired requests
.filter(TrackedOngoingRequest::isExpired)
.filter(OngoingRequest::isExpired)
.forEach(
request -> {
LOG.warn("Dropping expired request: {}", request);
Expand All @@ -97,8 +97,8 @@ void reap() {
* Fail all outstanding requests.
*/
private void failRequests() {
final Set<TrackedOngoingRequest> requests = ImmutableSet.copyOf(outstanding);
for (TrackedOngoingRequest id : requests) {
final Set<OngoingRequest> requests = ImmutableSet.copyOf(outstanding);
for (OngoingRequest id : requests) {
final boolean removed = outstanding.remove(id);
if (removed) {
id.reply(Response.forStatus(Status.SERVICE_UNAVAILABLE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@

import okio.ByteString;

class TrackedOngoingRequestImpl
extends ForwardingOngoingRequest
implements TrackedOngoingRequest {
class TrackedOngoingRequestImpl extends ForwardingOngoingRequest {

private final RequestTracker requestTracker;

TrackedOngoingRequestImpl(
OngoingRequest ongoingRequest,
RequestTracker requestTracker) {
TrackedOngoingRequestImpl(OngoingRequest ongoingRequest, RequestTracker requestTracker) {
super(ongoingRequest);
this.requestTracker = requestTracker;

Expand All @@ -51,10 +47,6 @@ public void drop() {
}
}

@Override
public void incrementDownstreamRequests() {
}

private boolean doReply(Response<ByteString> message) {
final boolean removed = requestTracker.remove(this);
if (removed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Runnable create(

incomingCallsGatherer.gatherIncomingCall(ongoingRequest, endpoint);

final TrackedOngoingRequest trackedRequest =
final OngoingRequest trackedRequest =
new TrackedOngoingRequestImpl(ongoingRequest, requestTracker);

return delegate.create(trackedRequest, requestContext, endpoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.io.IOException;
import java.util.Optional;
import java.util.concurrent.CompletionStage;
import java.util.function.BiConsumer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,44 @@

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import static org.mockito.Mockito.mock;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

@RunWith(MockitoJUnitRunner.class)
public class TrackedOngoingRequestImplTest {

private RequestTracker tracker = new RequestTracker();
@Mock OngoingRequest ongoingRequest;
@Mock RequestTracker requestTracker;

RequestTracker tracker = new RequestTracker();

@Before
public void setUp() {
public void setUp() throws Exception {
when(ongoingRequest.request()).thenReturn(Request.forUri("http://service/path"));
when(ongoingRequest.isExpired()).thenReturn(false);
}

@Test
public void shouldRegisterWithRequestTracker() throws Exception {
OngoingRequest tr = new TrackedOngoingRequestImpl(ongoingRequest, requestTracker);

verify(requestTracker).register(eq(tr));
}

@Test
public void shouldNotReplyIfNotTracked() throws Exception {
Request requestMessage = Request.forUri("http://service/path");
OngoingRequest ongoingRequest = mock(OngoingRequest.class);
when(ongoingRequest.request()).thenReturn(requestMessage);
when(ongoingRequest.isExpired()).thenReturn(false);

final TrackedOngoingRequest trackedOngoingRequest =
final OngoingRequest trackedOngoingRequest =
new TrackedOngoingRequestImpl(ongoingRequest, tracker);

tracker.remove(trackedOngoingRequest);
trackedOngoingRequest.reply(Response.ok());

verifyNoMoreInteractions(ongoingRequest);
}

}

This file was deleted.

1 change: 0 additions & 1 deletion apollo-api/src/main/java/com/spotify/apollo/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package com.spotify.apollo;

import java.io.Closeable;
import java.util.concurrent.CompletionStage;

import okio.ByteString;
Expand Down
8 changes: 4 additions & 4 deletions apollo-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ using `-D` command-line options. For example, `-Ddomain=example.org`
sets the `domain` config key to `example.org`.

Apollo Core also considers environment variables of the form
`SPOTIFY_X_Y=ab`. These are translated into configuration keys
of the form `x.y=ab`. The values of the environment variables are
treated as strings and copied verbatim; no special syntax is
supported.
`APOLLO_X_Y=ab`, where the `APOLLO` prefix is [configurable with `Service.Builder.withEnvVarPrefix()`](src/main/java/com/spotify/apollo/core/Service.java).
These are translated into configuration keys of the form `x.y=ab`.
The values of the environment variables are treated as strings and
copied verbatim; no special syntax is supported.

### Logging configuration

Expand Down
10 changes: 2 additions & 8 deletions apollo-core/src/main/java/com/spotify/apollo/core/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public interface Service {
* @return a new instance of this service that is up and running.
* @throws ApolloHelpException if the user wants to show command-line help and not start the
* application.
* @throws ApolloCompatException if Apollo compatibility mode was requested but the command line
* was not in the Apollo format.
* @throws ApolloCliException if something else related to CLI parsing failed.
* @throws java.io.IOException if the application could not start for some other reason.
*/
Expand All @@ -70,8 +68,6 @@ public interface Service {
* @return a new instance of this service that is up and running.
* @throws ApolloHelpException if the user wants to show command-line help and not start the
* application.
* @throws ApolloCompatException if Apollo compatibility mode was requested but the command line
* was not in the Apollo format.
* @throws ApolloCliException if something else related to CLI parsing failed.
* @throws java.io.IOException if the application could not start for some other reason.
*/
Expand All @@ -87,8 +83,6 @@ public interface Service {
* @return a new instance of this service that is up and running.
* @throws ApolloHelpException if the user wants to show command-line help and not start the
* application.
* @throws ApolloCompatException if Apollo compatibility mode was requested but the command line
* was not in the Apollo format.
* @throws ApolloCliException if something else related to CLI parsing failed.
* @throws java.io.IOException if the application could not start for some other reason.
*/
Expand Down Expand Up @@ -144,8 +138,8 @@ interface Builder {

/**
* Sets the prefix that is used to convert environment variables into configuration keys. By
* default, the prefix is {@code "SPOTIFY"}, which means that an environment variable like
* {@code "SPOTIFY_DOMAIN_NAME"} is translated into the config key {@code "domain.name"}.
* default, the prefix is {@code "APOLLO"}, which means that an environment variable like
* {@code "APOLLO_DOMAIN_NAME"} is translated into the config key {@code "domain.name"}.
*
* @param prefix The environment variable prefix to use.
* @return This builder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,6 @@ static Config parseArgs(
return config;
}

private static boolean flag(String arg) {
return arg.startsWith("-");
}

static Config appendConfig(Config config, String key, Object value, String description) {
return config.withValue(key, ConfigValueFactory.fromAnyRef(value, description));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.spotify.apollo.Request;
import com.spotify.apollo.Response;

import java.io.IOException;
import java.util.Optional;
import java.util.concurrent.CompletionStage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.spotify.apollo.Request;
import com.spotify.apollo.Response;

import java.io.IOException;
import java.util.Optional;
import java.util.concurrent.CompletionStage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@
import org.hamcrest.TypeSafeMatcher;

import java.io.Closeable;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.Executors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@
*/
package com.spotify.apollo.test.helper;

import com.spotify.apollo.Client;
import com.spotify.apollo.Environment;
import com.spotify.apollo.Request;
import com.spotify.apollo.Client;
import com.spotify.apollo.environment.ConfigUtil;
import com.spotify.apollo.route.AsyncHandler;
import com.spotify.apollo.route.Route;
import com.spotify.apollo.route.RouteProvider;

import java.util.concurrent.CompletionStage;
import java.util.stream.Stream;

import static com.spotify.apollo.environment.ConfigUtil.*;
import static com.spotify.apollo.environment.ConfigUtil.optionalString;
import static com.spotify.apollo.route.Route.async;
import static com.spotify.apollo.route.Route.sync;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ public void testParsesHeadersParameters() throws Exception {

Service service() {
return Services.usingName("test")
.withModule(HttpServerModule.create())
.build();
.withModule(HttpServerModule.create())
.build();
}

Config onPort(int port) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;

import java.io.IOException;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
Expand Down

0 comments on commit 672b7ba

Please sign in to comment.