Optimize some code (#3693)

* Optimize some code

* fix error of ImportOrder
This commit is contained in:
OLPMO
2020-01-14 09:32:00 +08:00
committed by Spencer Gibb
parent 23366ac178
commit a6da307048
9 changed files with 12 additions and 18 deletions

View File

@@ -57,7 +57,7 @@ public class TurbineController {
.interval(Duration.ofSeconds(5), Duration.ofSeconds(10))
.map(l -> Collections.singletonMap("type", (Object) "ping")).share();
flux = Flux.merge(RxReactiveStreams.toPublisher(stream), ping).share()
.map(map -> JsonUtility.mapToJson(map));
.map(JsonUtility::mapToJson);
}
@GetMapping(produces = MediaType.TEXT_EVENT_STREAM_VALUE)

View File

@@ -74,18 +74,14 @@ public class HystrixStreamAggregatorTests {
@Test
public void messageDecoded() throws Exception {
this.publisher.subscribe(map -> {
assertThat(map.get("type")).isEqualTo("HystrixCommand");
});
this.publisher.subscribe(map -> assertThat(map.get("type")).isEqualTo("HystrixCommand"));
this.aggregator.sendToSubject(PAYLOAD.getBytes());
this.output.expect(not(containsString("ERROR")));
}
@Test
public void messageWrappedInArray() throws Exception {
this.publisher.subscribe(map -> {
assertThat(map.get("type")).isEqualTo("HystrixCommand");
});
this.publisher.subscribe(map -> assertThat(map.get("type")).isEqualTo("HystrixCommand"));
this.aggregator.sendToSubject(new StringBuilder().append("[").append(PAYLOAD)
.append("]").toString().getBytes());
this.output.expect(not(containsString("ERROR")));
@@ -93,9 +89,7 @@ public class HystrixStreamAggregatorTests {
@Test
public void doubleEncodedMessage() throws Exception {
this.publisher.subscribe(map -> {
assertThat(map.get("type")).isEqualTo("HystrixCommand");
});
this.publisher.subscribe(map -> assertThat(map.get("type")).isEqualTo("HystrixCommand"));
// If The JSON is embedded in a JSON String this is what it looks like
String payload = "\"" + PAYLOAD.replace("\"", "\\\"") + "\"";
this.aggregator.sendToSubject(payload.getBytes());

View File

@@ -19,7 +19,6 @@ package org.springframework.cloud.netflix.turbine;
import com.netflix.config.DynamicBooleanProperty;
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;
import com.netflix.turbine.data.DataFromSingleInstance;
import com.netflix.turbine.discovery.Instance;
import com.netflix.turbine.handler.PerformanceCriteria;
import com.netflix.turbine.monitor.MonitorConsole;
@@ -37,7 +36,7 @@ public class SpringClusterMonitor extends AggregateClusterMonitor {
public SpringClusterMonitor(String name, String clusterName) {
super(name, new ObservationCriteria.ClusterBasedObservationCriteria(clusterName),
new PerformanceCriteria.AggClusterPerformanceCriteria(clusterName),
new MonitorConsole<DataFromSingleInstance>(), InstanceMonitorDispatcher,
new MonitorConsole<>(), InstanceMonitorDispatcher,
SpringClusterMonitor.ClusterConfigBasedUrlClosure);
}

View File

@@ -76,7 +76,7 @@ public class TurbineHttpTests {
@Override
public Collection<ClusterInformation> getClusterInformations(
HttpServletRequest request) {
List<ClusterInformation> clusterInformationList = new ArrayList<ClusterInformation>();
List<ClusterInformation> clusterInformationList = new ArrayList<>();
clusterInformationList.add(foo);
clusterInformationList.add(bar);
return clusterInformationList;

View File

@@ -122,7 +122,7 @@ public class LocationRewriteFilter extends ZuulFilter {
: redirectedUriComps.getPath();
if (downstreamHasGlobalPrefix(zuulProperties)) {
path.append("/" + zuulProperties.getPrefix());
path.append("/").append(zuulProperties.getPrefix());
}
else {
path.append(zuulHasGlobalPrefix(zuulProperties)

View File

@@ -270,7 +270,7 @@ public class SendResponseFilter extends ZuulFilter {
if (rd != null) {
StringBuilder debugHeader = new StringBuilder();
for (String it : rd) {
debugHeader.append("[[[" + it + "]]]");
debugHeader.append("[[[").append(it).append("]]]");
}
servletResponse.addHeader(X_ZUUL_DEBUG_HEADER, debugHeader.toString());
}

View File

@@ -235,7 +235,7 @@ public class RibbonRoutingFilter extends ZuulFilter {
throws ClientException, IOException {
RequestContext.getCurrentContext().set("zuulResponse", resp);
this.helper.setResponse(resp.getRawStatusCode(),
resp.getBody() == null ? null : resp.getBody(), resp.getHeaders());
resp.getBody(), resp.getHeaders());
}
}

View File

@@ -481,7 +481,7 @@ public class SimpleHostRoutingFilter extends ZuulFilter
try {
return Long.parseLong(contentLengthHeader);
}
catch (NumberFormatException e) {
catch (NumberFormatException ignored) {
}
}
return request.getContentLength();

View File

@@ -22,6 +22,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
@@ -98,7 +99,7 @@ public final class RequestContentDataExtractor {
if (listOfOnlyQueryParams != null) {
listOfOnlyQueryParams = listOfOnlyQueryParams.stream()
.filter(queryParam -> queryParam != null)
.filter(Objects::nonNull)
.map(param -> uriDecode(param, Charset.defaultCharset()))
.collect(Collectors.toList());
if (!listOfOnlyQueryParams.containsAll(listOfAllParams)) {