use of software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentRequest in project aws-iot-device-sdk-java-v2 by aws.
the class GreengrassV2ClientTest method testV2Client.
@Test
public void testV2Client() throws InterruptedException, ExecutionException, TimeoutException {
assertEquals(authenticationRequest.getAuthToken(), "myAuthToken");
CreateLocalDeploymentResponse depResp = client.createLocalDeployment(new CreateLocalDeploymentRequest());
assertEquals("deployment", depResp.getDeploymentId());
CompletableFuture<CreateLocalDeploymentResponse> asyncDepResp = client.createLocalDeploymentAsync(new CreateLocalDeploymentRequest());
assertEquals("deployment", asyncDepResp.get().getDeploymentId());
CompletableFuture<String> receivedMessage = new CompletableFuture<>();
CompletableFuture<String> finalReceivedMessage = receivedMessage;
GreengrassCoreIPCClientV2.StreamingResponse<SubscribeToTopicResponse, SubscribeToTopicResponseHandler> subResp = client.subscribeToTopic(new SubscribeToTopicRequest().withTopic("abc"), (x) -> {
if (!Thread.currentThread().getName().contains("pool")) {
System.out.println(Thread.currentThread().getName());
finalReceivedMessage.completeExceptionally(new RuntimeException("Ran on event loop instead of executor"));
}
finalReceivedMessage.complete(new String(x.getBinaryMessage().getMessage()));
}, Optional.empty(), Optional.empty());
assertEquals("message", receivedMessage.get());
subResp.getHandler().closeStream().get();
subscriptionClosed.get(1, TimeUnit.SECONDS);
subscriptionClosed = new CompletableFuture<>();
receivedMessage = new CompletableFuture<>();
CompletableFuture<String> finalReceivedMessage1 = receivedMessage;
subResp = client.subscribeToTopic(new SubscribeToTopicRequest().withTopic("abc"), new StreamResponseHandler<SubscriptionResponseMessage>() {
@Override
public void onStreamEvent(SubscriptionResponseMessage streamEvent) {
if (!Thread.currentThread().getName().contains("pool")) {
finalReceivedMessage1.completeExceptionally(new RuntimeException("Ran on event loop instead of executor"));
}
finalReceivedMessage1.complete(new String(streamEvent.getBinaryMessage().getMessage()));
}
@Override
public boolean onStreamError(Throwable error) {
return false;
}
@Override
public void onStreamClosed() {
}
});
assertEquals("message", receivedMessage.get());
subResp.getHandler().closeStream().get();
subscriptionClosed.get(1, TimeUnit.SECONDS);
subscriptionClosed = new CompletableFuture<>();
receivedMessage = new CompletableFuture<>();
CompletableFuture<String> finalReceivedMessage2 = receivedMessage;
GreengrassCoreIPCClientV2.StreamingResponse<CompletableFuture<SubscribeToTopicResponse>, SubscribeToTopicResponseHandler> subRespAsync = client.subscribeToTopicAsync(new SubscribeToTopicRequest().withTopic("abc"), new StreamResponseHandler<SubscriptionResponseMessage>() {
@Override
public void onStreamEvent(SubscriptionResponseMessage streamEvent) {
if (!Thread.currentThread().getName().contains("pool")) {
finalReceivedMessage2.completeExceptionally(new RuntimeException("Ran on event loop instead of executor"));
}
finalReceivedMessage2.complete(new String(streamEvent.getBinaryMessage().getMessage()));
}
@Override
public boolean onStreamError(Throwable error) {
return false;
}
@Override
public void onStreamClosed() {
}
});
assertEquals("message", receivedMessage.get());
subRespAsync.getHandler().closeStream().get();
subscriptionClosed.get(1, TimeUnit.SECONDS);
subscriptionClosed = new CompletableFuture<>();
receivedMessage = new CompletableFuture<>();
CompletableFuture<String> finalReceivedMessage3 = receivedMessage;
subRespAsync = client.subscribeToTopicAsync(new SubscribeToTopicRequest().withTopic("abc"), (x) -> {
if (!Thread.currentThread().getName().contains("pool")) {
finalReceivedMessage3.completeExceptionally(new RuntimeException("Ran on event loop instead of executor"));
}
finalReceivedMessage3.complete(new String(x.getBinaryMessage().getMessage()));
}, Optional.empty(), Optional.empty());
assertEquals("message", receivedMessage.get());
subRespAsync.getHandler().closeStream().get();
subscriptionClosed.get(1, TimeUnit.SECONDS);
}
use of software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentRequest in project aws-iot-device-sdk-java-v2 by aws.
the class GreengrassV2ClientTest method before.
@BeforeEach
public void before() throws IOException {
port = randomPort();
try (final EventLoopGroup elGroup = new EventLoopGroup(1);
SocketOptions socketOptions = new SocketOptions()) {
socketOptions.connectTimeoutMs = 3000;
socketOptions.domain = SocketOptions.SocketDomain.IPv4;
socketOptions.type = SocketOptions.SocketType.STREAM;
GreengrassCoreIPCService service = new GreengrassCoreIPCService();
service.setCreateLocalDeploymentHandler((c) -> new GeneratedAbstractCreateLocalDeploymentOperationHandler(c) {
@Override
protected void onStreamClosed() {
}
@Override
public CreateLocalDeploymentResponse handleRequest(CreateLocalDeploymentRequest request) {
return new CreateLocalDeploymentResponse().withDeploymentId("deployment");
}
@Override
public void handleStreamEvent(EventStreamJsonMessage streamRequestEvent) {
}
});
service.setSubscribeToTopicHandler((c) -> new GeneratedAbstractSubscribeToTopicOperationHandler(c) {
@Override
protected void onStreamClosed() {
subscriptionClosed.complete(null);
}
@Override
public SubscribeToTopicResponse handleRequest(SubscribeToTopicRequest request) {
new Thread(() -> {
sendStreamEvent(new SubscriptionResponseMessage().withBinaryMessage(new BinaryMessage().withMessage("message".getBytes(StandardCharsets.UTF_8))));
}).start();
return new SubscribeToTopicResponse().withTopicName(request.getTopic());
}
@Override
public void handleStreamEvent(EventStreamJsonMessage streamRequestEvent) {
}
});
service.setAuthenticationHandler((headers, bytes) -> {
authenticationRequest = new Gson().fromJson(new String(bytes), GreengrassEventStreamConnectMessage.class);
return () -> "connected";
});
service.setAuthorizationHandler(authenticationData -> Authorization.ACCEPT);
ipcServer = new RpcServer(elGroup, socketOptions, null, "127.0.0.1", port, service);
ipcServer.runServer();
client = GreengrassCoreIPCClientV2.builder().withPort(port).withSocketPath("127.0.0.1").withSocketDomain(SocketOptions.SocketDomain.IPv4).withAuthToken("myAuthToken").build();
}
}
use of software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentRequest in project aws-greengrass-cli by aws-greengrass.
the class DeploymentCommandTest method GIVEN_WHEN_recipe_dir_is_provided_THEN_request_contains_provided_recipe_dir.
@Test
void GIVEN_WHEN_recipe_dir_is_provided_THEN_request_contains_provided_recipe_dir() {
int exitCode = runCommandLine("deployment", "create", "--recipeDir", RECIPE_FOLDER_PATH_STR);
CreateLocalDeploymentRequest request = new CreateLocalDeploymentRequest();
request.setRecipeDirectoryPath(deTilde(RECIPE_FOLDER_PATH_STR).get().toString());
verify(nucleusAdapteripc).createLocalDeployment(request);
assertThat(exitCode, is(0));
}
use of software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentRequest in project aws-greengrass-cli by aws-greengrass.
the class DeploymentCommandTest method GIVEN_WHEN_configs_are_provided_THEN_request_contain_all_config.
@Test
void GIVEN_WHEN_configs_are_provided_THEN_request_contain_all_config() throws JsonProcessingException {
String updateConfigString = "{ \"Component1\": { \"MERGE\": { \"Company\": { \"Office\": { \"temperature\": 22 } }, \"path1\": { \"Object2\": { \"key2\": \"val2\" } } } }, \"Component2\": { \"RESET\": [ \"/secret/first\" ] } }";
int exitCode = runCommandLine("deployment", "create", "--update-config", updateConfigString);
Map<String, Map<String, Object>> componentNameToConfig = mapper.readValue(updateConfigString, Map.class);
CreateLocalDeploymentRequest request = new CreateLocalDeploymentRequest();
request.setComponentToConfiguration(componentNameToConfig);
verify(nucleusAdapteripc).createLocalDeployment(request);
assertThat(exitCode, is(0));
}
use of software.amazon.awssdk.aws.greengrass.model.CreateLocalDeploymentRequest in project aws-greengrass-cli by aws-greengrass.
the class DeploymentCommandTest method GIVEN_WHEN_components_runwith_provided_THEN_request_contains_the_info.
@Test
void GIVEN_WHEN_components_runwith_provided_THEN_request_contains_the_info() throws Exception {
int exitCode = runCommandLine("deployment", "create", "--runWith", "Component1:windowsUser=foobar", "--runWith", "Component2:windowsUser=foobar", "--runWith", "Component2:posixUser=1234", "--systemLimits", Paths.get(this.getClass().getResource("resource_limits.json").toURI()).toString());
Map<String, RunWithInfo> componentToRunWithInfo = new HashMap<>();
RunWithInfo runWithInfo = new RunWithInfo();
runWithInfo.setWindowsUser("foobar");
MapType mapType = mapper.getTypeFactory().constructMapType(HashMap.class, String.class, SystemResourceLimits.class);
Map<String, SystemResourceLimits> systemResourceLimits = mapper.readValue(getClass().getResource("resource_limits.json"), mapType);
runWithInfo.setSystemResourceLimits(systemResourceLimits.get("Component1"));
componentToRunWithInfo.put("Component1", runWithInfo);
runWithInfo = new RunWithInfo();
runWithInfo.setPosixUser("1234");
runWithInfo.setWindowsUser("foobar");
componentToRunWithInfo.put("Component2", runWithInfo);
CreateLocalDeploymentRequest request = new CreateLocalDeploymentRequest();
request.setComponentToRunWithInfo(componentToRunWithInfo);
verify(nucleusAdapteripc).createLocalDeployment(request);
assertThat(exitCode, is(0));
}
Aggregations