Modified version determination for user-agent, added test
This commit is contained in:
@@ -64,9 +64,9 @@ public final class CustomRuntimeEventLoop implements SmartLifecycle {
|
||||
private static final String LAMBDA_RUNTIME_URL_TEMPLATE = "http://{0}/{1}/runtime/invocation/next";
|
||||
private static final String LAMBDA_INVOCATION_URL_TEMPLATE = "http://{0}/{1}/runtime/invocation/{2}/response";
|
||||
private static final String USER_AGENT_VALUE = String.format(
|
||||
"spring-cloud-function/%s-%s",
|
||||
System.getProperty("java.vendor.version"),
|
||||
CustomRuntimeEventLoop.class.getPackage().getImplementationVersion());
|
||||
"spring-cloud-function:%s/JAVA-%s",
|
||||
extractVersion(),
|
||||
System.getProperty("java.vm.name"));
|
||||
|
||||
private final ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@@ -85,6 +85,22 @@ public final class CustomRuntimeEventLoop implements SmartLifecycle {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
this.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
this.executor.shutdownNow();
|
||||
this.running = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRunning() {
|
||||
return this.running;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void eventLoop(ConfigurableApplicationContext context) {
|
||||
Environment environment = context.getEnvironment();
|
||||
@@ -205,19 +221,13 @@ public final class CustomRuntimeEventLoop implements SmartLifecycle {
|
||||
return value instanceof Collection ? (Collection<?>) value : Arrays.asList(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
this.run();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
this.executor.shutdownNow();
|
||||
this.running = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRunning() {
|
||||
return this.running;
|
||||
private static String extractVersion() {
|
||||
String path = CustomRuntimeEventLoop.class.getProtectionDomain().getCodeSource().getLocation().toString();
|
||||
int endIndex = path.lastIndexOf('.');
|
||||
if (endIndex < 0) {
|
||||
return "UNKNOWN-VERSION";
|
||||
}
|
||||
int startIndex = path.lastIndexOf("/") + 1;
|
||||
return path.substring(startIndex, endIndex).replace("spring-cloud-function-adapter-aws-", "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.cloud.function.adapter.test.aws.AWSCustomRuntime;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
@@ -46,6 +47,9 @@ public class CustomRuntimeEventLoopTest {
|
||||
.run()) {
|
||||
|
||||
AWSCustomRuntime aws = userContext.getBean(AWSCustomRuntime.class);
|
||||
Message<String> replyMessage = aws.exchange("\"ricky\"");
|
||||
assertThat(replyMessage.getHeaders()).containsKey("user-agent");
|
||||
assertThat(((String) replyMessage.getHeaders().get("user-agent"))).startsWith("spring-cloud-function:");
|
||||
assertThat(aws.exchange("\"ricky\"").getPayload()).isEqualTo("\"RICKY\"");
|
||||
assertThat(aws.exchange("\"julien\"").getPayload()).isEqualTo("\"JULIEN\"");
|
||||
assertThat(aws.exchange("\"bubbles\"").getPayload()).isEqualTo("\"BUBBLES\"");
|
||||
|
||||
Reference in New Issue
Block a user