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

Return supported query types for unsupported queries #360

Merged
merged 11 commits into from Feb 26, 2021
1 change: 1 addition & 0 deletions temporal-sdk/build.gradle
Expand Up @@ -55,6 +55,7 @@ dependencies {
testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
testImplementation group: 'com.googlecode.junit-toolbox', name: 'junit-toolbox', version: '2.4'
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.8.0'
}

configurations.all {
Expand Down
Expand Up @@ -75,7 +75,8 @@ public Optional<Payloads> handleQuery(String queryName, Optional<Payloads> input
Object[] args;
if (handler == null) {
if (dynamicQueryHandler == null) {
throw new IllegalStateException("Unknown query type: " + queryName);
throw new IllegalArgumentException(
"Unknown query type: " + queryName + ", knownTypes=" + queryCallbacks.keySet());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you comment a sample string of this output? I want to test with the web

}
args = new Object[] {new EncodedValues(input, converter)};
} else {
Expand Down
Expand Up @@ -23,7 +23,7 @@
import static junit.framework.TestCase.assertNotNull;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
Expand Up @@ -697,7 +697,7 @@ public void workflowThreadsWillEvictCacheWhenMaxThreadCountIsHit() throws Throwa
// Wait for reporter
Thread.sleep(600);
verify(reporter, atLeastOnce())
.reportCounter(eq(MetricsType.STICKY_CACHE_THREAD_FORCED_EVICTION), eq(tags), anyInt());
.reportCounter(eq(MetricsType.STICKY_CACHE_THREAD_FORCED_EVICTION), eq(tags), anyLong());
}

@Test
Expand Down
@@ -0,0 +1,85 @@
/*
* Copyright (C) 2020 Temporal Technologies, Inc. All Rights Reserved.
*
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Modifications copyright (C) 2017 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. A copy of the License is
* located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package io.temporal.internal.sync;

import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import io.temporal.api.common.v1.Payloads;
import io.temporal.common.converter.DataConverter;
import io.temporal.common.interceptors.WorkflowInboundCallsInterceptor;
import io.temporal.common.interceptors.WorkflowOutboundCallsInterceptor;
import java.lang.reflect.Type;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;

public class QueryDispatcherTest {

private QueryDispatcher dispatcher;

@Before
public void init() {
initializeDispatcher("QueryA", "QueryB");
}

private QueryDispatcher initializeDispatcher(String... queries) {
// Initialize the dispatcher.
dispatcher = new QueryDispatcher(DataConverter.getDefaultInstance());
for (String query : queries) {
WorkflowOutboundCallsInterceptor.RegisterQueryInput request =
new WorkflowOutboundCallsInterceptor.RegisterQueryInput(
query, new Class[] {}, new Type[] {}, null);
dispatcher.registerQueryHandlers(request);
}
return dispatcher;
}

@Test
public void testQuerySuccess() {
// Set up a mock interceptor.
WorkflowInboundCallsInterceptor.QueryOutput queryOutput =
new WorkflowInboundCallsInterceptor.QueryOutput("dummy");
WorkflowInboundCallsInterceptor mockInterceptor = mock(WorkflowInboundCallsInterceptor.class);
when(mockInterceptor.handleQuery(any())).thenReturn(queryOutput);

// Initialize the dispatcher.
dispatcher.setInboundCallsInterceptor(mockInterceptor);

// Invoke functionality under test, expect no exceptions for an existing query.
Optional<Payloads> queryResult = dispatcher.handleQuery("QueryB", Optional.empty());
assertTrue(queryResult.isPresent());
}

@Test
public void testQueryDispatcherException() {
// Invoke functionality under test, expect an exception with the correct output for a
// non-existing query.
Throwable exception =
assertThrows(
IllegalArgumentException.class,
() -> {
dispatcher.handleQuery("QueryC", null);
});
assertEquals("Unknown query type: QueryC, knownTypes=[QueryA, QueryB]", exception.getMessage());
}
vkoby marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Up @@ -20,7 +20,7 @@
package io.temporal.internal.testing;

import static org.junit.Assert.*;
import static org.mockito.Matchers.anyString;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
Expand Up @@ -22,7 +22,7 @@
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down
2 changes: 1 addition & 1 deletion temporal-serviceclient/build.gradle
Expand Up @@ -87,9 +87,9 @@ dependencies {
if (!JavaVersion.current().isJava8()) {
implementation 'javax.annotation:javax.annotation-api:1.3.2'
}

testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
testImplementation group: 'com.googlecode.junit-toolbox', name: 'junit-toolbox', version: '2.4'
testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.8.0'
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
}

Expand Down