-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix durable return type void issue (#711)
* fix durable return type void issue add unit tests * fix stupid test name
- Loading branch information
Showing
3 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/test/java/com/microsoft/azure/functions/worker/broker/ParameterResolverTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.microsoft.azure.functions.worker.broker; | ||
|
||
import com.microsoft.azure.functions.rpc.messages.RpcException; | ||
import com.microsoft.azure.functions.spi.inject.FunctionInstanceInjector; | ||
import com.microsoft.azure.functions.worker.WorkerLogManager; | ||
import com.microsoft.azure.functions.worker.binding.BindingDataStore; | ||
import com.microsoft.azure.functions.worker.binding.ExecutionContextDataSource; | ||
import com.microsoft.azure.functions.worker.binding.ExecutionRetryContext; | ||
import com.microsoft.azure.functions.worker.binding.ExecutionTraceContext; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.logging.Logger; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.when; | ||
|
||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class ParameterResolverTest { | ||
|
||
private ExecutionContextDataSource executionContextDataSource; | ||
@Mock | ||
private MethodBindInfo methodBindInfo; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
String invocationId = "testInvocationId"; | ||
ExecutionTraceContext traceContext = new ExecutionTraceContext("traceParent", "traceState", new HashMap<>()); | ||
ExecutionRetryContext retryContext = new ExecutionRetryContext(1, 2, RpcException.newBuilder().build()); | ||
String functionName = "ParameterResolverTest"; | ||
BindingDataStore dataStore = new BindingDataStore(); | ||
dataStore.setBindingDefinitions(new HashMap<>()); | ||
try (MockedStatic<WorkerLogManager> workerLogManagerMockedStatic = Mockito.mockStatic(WorkerLogManager.class)) { | ||
workerLogManagerMockedStatic.when(() -> WorkerLogManager.getInvocationLogger(invocationId)) | ||
.thenReturn(Logger.getAnonymousLogger()); | ||
executionContextDataSource = new ExecutionContextDataSource(invocationId, | ||
traceContext, retryContext, functionName, dataStore, methodBindInfo, | ||
this.getClass(), new ArrayList<>(), new FunctionInstanceInjector() { | ||
@Override | ||
public <T> T getInstance(Class<T> functionClass) throws Exception { | ||
return null; | ||
} | ||
}); | ||
} | ||
|
||
} | ||
|
||
@Test | ||
public void testResolveArgumentsHasImplicitOutputTrue() throws Exception { | ||
Method testMethod = this.getClass().getDeclaredMethod("testMethod"); | ||
when(methodBindInfo.hasImplicitOutput()).thenReturn(true); | ||
when(methodBindInfo.getMethod()).thenReturn(testMethod); | ||
when(methodBindInfo.getParams()).thenReturn(new ArrayList<>()); | ||
ParameterResolver.resolveArguments(executionContextDataSource); | ||
assertTrue(executionContextDataSource.getDataStore().getDataTargetTypedValue(BindingDataStore.RETURN_NAME).isPresent()); | ||
} | ||
|
||
@Test | ||
public void testResolveArgumentsHasImplicitOutputFalse() throws Exception { | ||
Method testMethod = this.getClass().getDeclaredMethod("testMethod"); | ||
when(methodBindInfo.hasImplicitOutput()).thenReturn(false); | ||
when(methodBindInfo.getMethod()).thenReturn(testMethod); | ||
when(methodBindInfo.getParams()).thenReturn(new ArrayList<>()); | ||
ParameterResolver.resolveArguments(executionContextDataSource); | ||
assertFalse(executionContextDataSource.getDataStore().getDataTargetTypedValue(BindingDataStore.RETURN_NAME).isPresent()); | ||
} | ||
|
||
public void testMethod() {} | ||
} |