Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor for better testing #590

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
25c16fe
Extract Invoke interface
pawelprazak May 12, 2022
61210f7
Extract Call interface
pawelprazak May 12, 2022
554c39d
Prune code unused because of previous refactoring
pawelprazak May 12, 2022
db378ba
Move DefaultRunner constants to Runner interface
pawelprazak May 12, 2022
d1f14d5
Simplify Runner interface
pawelprazak May 12, 2022
8f5ec8e
New minimal test framework
pawelprazak May 12, 2022
9dd574e
Make monitor mocks more usable
pawelprazak May 12, 2022
8f15cca
Move TestOptions, rename getters
pawelprazak May 12, 2022
28a3893
Port ReSerializerTest to new framework
pawelprazak May 13, 2022
c03dac8
Port DeploymentExceptionTest to new framework
pawelprazak May 13, 2022
918f2e0
Port ResourceRefPropertyTest to new framework
pawelprazak May 13, 2022
3682237
Port ConstructorConfusionTest to new framework
pawelprazak May 13, 2022
f862d3f
Move MockCallArgs, MockEngine, MockMonitor to test package
pawelprazak May 13, 2022
d134eda
Move InMemoryLogger to test package
pawelprazak May 13, 2022
74ff001
Port MonitorMocksTest to new framework
pawelprazak May 13, 2022
13b33e9
Port DeploymentRunnerTest to new framework
pawelprazak May 13, 2022
ab34d17
Port DeploymentInvokeTest, DeploymentResourceDependencyGatheringTest,…
pawelprazak May 13, 2022
7ea3691
Remove PULUMI_JAVA_TASK_TIMEOUT_IN_MILLIS
pawelprazak May 13, 2022
186a500
Port DeploymentTest, ResourceTest to new framework
pawelprazak May 13, 2022
311ce1d
Remove @Deprecated code unused by the new framework
pawelprazak May 13, 2022
bfd1d61
Move helpers from DeploymentTests to PulumiTestInternal
pawelprazak May 13, 2022
df87a31
Port DeploymentInstanceTest and StackTest to new framework
pawelprazak May 13, 2022
40e9ace
Remove dependency on Mockito in SDK
pawelprazak May 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ env:
PULUMI_API: https://api.pulumi-staging.io
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
AWS_REGION: us-west-2
PULUMI_JAVA_TASK_TIMEOUT_IN_MILLIS: 300000
GPR_USER: ${{ secrets.GPR_USER }}
GPR_TOKEN: ${{ secrets.GPR_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 1 addition & 2 deletions sdk/java/pulumi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ dependencies {
implementation("com.google.code.gson:gson:2.8.6") // make sure we don't clash with grpc deps
implementation("com.google.protobuf:protobuf-java:3.12.0") // make sure we don't clash with grpc deps
implementation("com.google.protobuf:protobuf-java-util:3.12.0") // make sure we don't clash with grpc deps
implementation("org.mockito:mockito-core:3.12.4")

testImplementation("io.grpc:grpc-testing:${grpcVersion}")

Expand All @@ -48,7 +47,7 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-params:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
testImplementation("org.assertj:assertj-core:3.20.2")

testImplementation("org.mockito:mockito-core:3.12.4")
testImplementation("nl.jqno.equalsverifier:equalsverifier:3.6.1")
testImplementation("org.junit-pioneer:junit-pioneer:1.6.2")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import com.pulumi.resources.ProviderResource.ProviderResourceInternal;
import com.pulumi.resources.Resource;
import com.pulumi.resources.Resource.ResourceInternal;
import com.pulumi.resources.Stack;
import com.pulumi.resources.Stack.StackInternal;

public class Internal {

Expand Down Expand Up @@ -48,10 +46,6 @@ public static InputArgsInternal from(InputArgs a) {
return InputArgsInternal.from(a);
}

public static StackInternal from(Stack s) {
return StackInternal.from(s);
}

public static ProviderResourceInternal from(ProviderResource r) {
return ProviderResourceInternal.from(r);
}
Expand Down
214 changes: 6 additions & 208 deletions sdk/java/pulumi/src/main/java/com/pulumi/deployment/Deployment.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
package com.pulumi.deployment;

import com.google.common.collect.ImmutableMap;
import com.pulumi.core.Output;
import com.pulumi.core.TypeShape;
import com.pulumi.deployment.internal.Call;
import com.pulumi.deployment.internal.DeploymentInstanceHolder;
import com.pulumi.deployment.internal.DeploymentInternal;
import com.pulumi.resources.CallArgs;
import com.pulumi.resources.InvokeArgs;
import com.pulumi.resources.Resource;
import com.pulumi.resources.Stack;
import com.pulumi.resources.StackOptions;
import com.pulumi.deployment.internal.Invoke;
import com.pulumi.deployment.internal.RegisterResourceOutputs;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;

public interface Deployment {
public interface Deployment extends Invoke, Call, RegisterResourceOutputs {

/**
* The current running deployment instance. This is only available from inside the function
* passed to @see {@link Deployment#runAsync(Supplier)} (or its overloads).
* passed to @see {@link com.pulumi.deployment.internal.Runner#registerAndRunAsync(Supplier)} (or its overloads).
*
* @throws IllegalStateException if called before 'run' was called
*/
Expand All @@ -42,202 +33,9 @@ static DeploymentInstance getInstance() {
String getProjectName();

/**
* Whether or not the application is currently being previewed or actually applied.
* Whether the application is currently being previewed or actually applied.
*
* @return true if application is being applied
*/
boolean isDryRun();

/**
* Dynamically invokes the function {@code token}, which is offered by a provider plugin.
* <p>
* The result of {@code invoke} will be an @see {@link Output}{@literal <T>} resolved to the
* result value of the provider plugin.
* <p>
* The {@code args} inputs can be a bag of computed values
* (including, {@code T}s, @see {@link CompletableFuture}s, @see {@link com.pulumi.core.Output}s, etc.)
*/
<T> Output<T> invoke(String token, TypeShape<T> targetType, InvokeArgs args, @Nullable InvokeOptions options);

/**
* Same as @see {@link #invoke(String, TypeShape, InvokeArgs, InvokeOptions)}
*/
<T> Output<T> invoke(String token, TypeShape<T> targetType, InvokeArgs args);

/**
* Dynamically invokes the function {@code token}, which is offered by a provider plugin.
* <p>
* The result of {@code invokeAsync} will be a @see {@link CompletableFuture} resolved to the
* result value of the provider plugin.
* <p>
* The {@code args} inputs can be a bag of computed values
* (including, {@code T}s, @see {@link CompletableFuture}s, @see {@link com.pulumi.core.Output}s, etc.).
*/
<T> CompletableFuture<T> invokeAsync(String token, TypeShape<T> targetType, InvokeArgs args, InvokeOptions options);

/**
* Same as @see {@link #invokeAsync(String, TypeShape, InvokeArgs, InvokeOptions)}
*/
<T> CompletableFuture<T> invokeAsync(String token, TypeShape<T> targetType, InvokeArgs args);

/**
* Same as @see {@link #invokeAsync(String, TypeShape, InvokeArgs, InvokeOptions)}, however the return value is ignored.
*/
CompletableFuture<Void> invokeAsync(String token, InvokeArgs args, InvokeOptions options);

/**
* Same as @see {@link #invokeAsync(String, TypeShape, InvokeArgs, InvokeOptions)}, however the return value is ignored.
*/
CompletableFuture<Void> invokeAsync(String token, InvokeArgs args);

/**
* Dynamically calls the function {@code token}, which is offered by a provider plugin.
* <p>
* The result of {@code call} will be an @see {@link Output}{@literal <T>} resolved to the
* result value of the provider plugin.
* <p>
* The {@code args} inputs can be a bag of computed values
* (including, {@code T}s, @see {@link CompletableFuture}s, @see {@link com.pulumi.core.Output}s, etc.).
*/
<T> Output<T> call(String token, TypeShape<T> targetType, CallArgs args, @Nullable Resource self, @Nullable CallOptions options);

/**
* Same as {@link #call(String, TypeShape, CallArgs, Resource, CallOptions)}
*/
<T> Output<T> call(String token, TypeShape<T> targetType, CallArgs args, @Nullable Resource self);

/**
* Same as {@link #call(String, TypeShape, CallArgs, Resource, CallOptions)}
*/
<T> Output<T> call(String token, TypeShape<T> targetType, CallArgs args);

/**
* Same as {@link #call(String, TypeShape, CallArgs, Resource, CallOptions)}, however the return value is ignored.
*/
void call(String token, CallArgs args, @Nullable Resource self, @Nullable CallOptions options);

/**
* Same as {@link #call(String, TypeShape, CallArgs, Resource, CallOptions)}, however the return value is ignored.
*/
void call(String token, CallArgs args, @Nullable Resource self);

/**
* Same as {@link #call(String, TypeShape, CallArgs, Resource, CallOptions)}, however the return value is ignored.
*/
void call(String token, CallArgs args);

/**
* An entry-point to a Pulumi application.
* @param callback Callback that creates stack resources.
* @see #runAsyncFuture(Supplier, StackOptions) for more details.
*/
static CompletableFuture<Integer> runAsyncRunnable(Runnable callback) {
return runAsync(() -> {
callback.run();
return ImmutableMap.of();
});
}

/**
* An entry-point to a Pulumi application.
* Deployment will instantiate a default stack instance based on the callback passed as {@code callback} parameter.
* @param callback Callback that creates stack resources.
* @return A dictionary of stack outputs.
* @see #runAsyncFuture(Supplier, StackOptions) for more details.
*/
static CompletableFuture<Integer> runAsync(Supplier<Map<String, Output<?>>> callback) {
return runAsyncFuture(() -> CompletableFuture.supplyAsync(callback));
}

/**
* An entry-point to a Pulumi application.
* Deployment will instantiate a default stack instance based on the callback passed as {@code callback} parameter.
* @param callback Callback that creates stack resources.
* @see #runAsyncFuture(Supplier, StackOptions) for more details.
*/
static CompletableFuture<Integer> runAsyncFuture(
Supplier<CompletableFuture<Map<String, Output<?>>>> callback
) {
return runAsyncFuture(callback, null);
}

/**
* An entry-point to a Pulumi application.
* Deployment will instantiate a default stack instance based on the callback passed as {@code callback} parameter.
* @param callback Callback that creates stack resources.
* @param options Optional Stack options.
* Java applications should perform all startup logic
* they need in their {@code main} method and then end with:
* <p>
* <code>
* public static void main(String[] args) {
* // program initialization code ...
*
* return Deployment.runAsync(() -{@literal >} {
* // Code that creates resources.
* });
* }
* </code>
* </p>
* <p>
* Importantly: Cloud resources cannot be created outside of the lambda passed
* to any of the @see #runAsync overloads.
* </p>
* <p>
* Because cloud Resource construction is inherently asynchronous,
* the result of this function is a @see {@link CompletableFuture} which should
* then be returned or awaited. This will ensure that any problems that are
* encountered during the running of the program are properly reported.
* Failure to do this may lead to the program ending early before all
* resources are properly registered.
* </p>
* The function passed to @see #runAsyncFuture(Supplier, StackOptions)
* can optionally return a @see {@link java.util.Map}.
* The keys and values in this map will become the outputs for the Pulumi Stack that is created.
* @see #runAsyncStack(Supplier) for more information.
*/
static CompletableFuture<Integer> runAsyncFuture(
Supplier<CompletableFuture<Map<String, Output<?>>>> callback,
@Nullable StackOptions options
) {
return DeploymentInternal.createRunnerAndRunAsync(
DeploymentInternal.deploymentFactory(),
runner -> runner.runAsyncFuture(callback, options)
);
}

/**
* An entry-point to a Pulumi application.
* Deployment will instantiate a new stack instance using the supplier passed as {@code stackFactory} parameter.
* @param stackFactory The stack supplier used to create stack instances
* Java applications should perform all startup logic they
* need in their {@code main} method and then end with:
* <p>
* <code>
* public static void main(String[] args) {
* // program initialization code ...
*
* {@literal return Deployment.runAsyncStack(() -> new MyStack()));}
* }
* </code>
* </p>
* <p>
* Importantly: cloud resources cannot be created outside of the @see Stack component.
* </p>
* <p>
* Because cloud Resource construction is inherently asynchronous, the
* result of this function is a @see {@link CompletableFuture} which should then
* be returned or awaited. This will ensure that any problems that are
* encountered during the running of the program are properly reported.
* Failure to do this may lead to the program ending early before all
* resources are properly registered.
* </p>
* @see #runAsyncFuture(Supplier, StackOptions) for more information.
*/
static <S extends Stack> CompletableFuture<Integer> runAsyncStack(Supplier<S> stackFactory) {
return DeploymentInternal.createRunnerAndRunAsync(
DeploymentInternal.deploymentFactory(),
runner -> runner.runAsync(stackFactory)
);
}
}

This file was deleted.

30 changes: 0 additions & 30 deletions sdk/java/pulumi/src/main/java/com/pulumi/deployment/Mocks.java

This file was deleted.

Loading