Skip to content

Commit c57c685

Browse files
committed
fix flaky test and add test
1 parent 0533432 commit c57c685

19 files changed

+593
-161
lines changed
Lines changed: 78 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,94 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
7+
* use this file except in compliance with the License. A copy of the License is
8+
* located at
9+
*
10+
* http://aws.amazon.com/apache2.0
11+
*
12+
* or in the "license" file accompanying this file. This file is distributed on
13+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
* express or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
118
package com.uber.cadence.internal.compatibility.proto;
219

320
import com.google.protobuf.Any;
421
import com.google.protobuf.InvalidProtocolBufferException;
5-
import com.google.protobuf.Message;
622
import com.google.rpc.Status;
723
import com.uber.cadence.api.v1.*;
824
import com.uber.cadence.serviceclient.exceptions.*;
925
import io.grpc.StatusRuntimeException;
1026
import io.grpc.protobuf.StatusProto;
1127

1228
public class ErrorMapper {
13-
public static ServiceClientException Error(StatusRuntimeException e) {
29+
public static ServiceClientException Error(StatusRuntimeException e) {
1430

15-
Status status = StatusProto.fromThrowable(e);
16-
if (status == null || status.getDetailsCount() == 0) {
17-
return new ServiceClientException("empty status or status with empty details", e);
18-
}
31+
Status status = StatusProto.fromThrowable(e);
32+
if (status == null) {
33+
return new ServiceClientException("empty status", e);
34+
}
1935

20-
Any detail = status.getDetails(0);
36+
Any detail = Any.getDefaultInstance();
37+
if (status.getDetailsCount() > 0) {
38+
detail = status.getDetails(0);
39+
}
2140

22-
try {
23-
switch (e.getStatus().getCode()) {
24-
case PERMISSION_DENIED:
25-
return new AccessDeniedException(e);
26-
case INTERNAL:
27-
return new InternalServiceException(e);
28-
case NOT_FOUND:
29-
if (detail.is(WorkflowExecutionAlreadyCompletedError.class)) {
30-
return new WorkflowExecutionAlreadyCompletedException(e);
31-
} else {
32-
return new EntityNotExistsException(e);
33-
}
34-
case ALREADY_EXISTS:
35-
if (detail.is(CancellationAlreadyRequestedError.class)) {
36-
return new CancellationAlreadyRequestedException(e);
37-
} else if (detail.is(DomainAlreadyExistsError.class)) {
38-
return new DomainAlreadyExistsException(e);
39-
} else if (detail.is(WorkflowExecutionAlreadyStartedError.class)) {
40-
WorkflowExecutionAlreadyStartedError error = detail.unpack(WorkflowExecutionAlreadyStartedError.class);
41-
return new WorkflowExecutionAlreadyStartedException(error.getStartRequestId(), error.getRunId());
42-
}
43-
case DATA_LOSS:
44-
return new InternalDataInconsistencyException(e);
45-
case FAILED_PRECONDITION:
46-
if (detail.is(ClientVersionNotSupportedError.class)) {
47-
ClientVersionNotSupportedError error = detail.unpack(ClientVersionNotSupportedError.class);
48-
return new ClientVersionNotSupportedException(error.getFeatureVersion(), error.getClientImpl(), error.getSupportedVersions());
49-
}else if (detail.is(FeatureNotEnabledError.class)) {
50-
FeatureNotEnabledError error = detail.unpack(FeatureNotEnabledError.class);
51-
return new FeatureNotEnabledException(error.getFeatureFlag());
52-
} else if (detail.is(DomainNotActiveError.class)) {
53-
DomainNotActiveError error = detail.unpack(DomainNotActiveError.class);
54-
return new DomainNotActiveException(error.getDomain(), error.getCurrentCluster(), error.getActiveCluster());
55-
}
56-
case RESOURCE_EXHAUSTED:
57-
if (detail.is(LimitExceededError.class)) {
58-
return new LimitExceededException(e);
59-
} else {
60-
return new ServiceBusyException(e);
61-
}
62-
case UNKNOWN:
63-
default:
64-
return new ServiceClientException(e);
65-
}
66-
} catch (InvalidProtocolBufferException ex) {
67-
return new ServiceClientException(ex);
68-
}
41+
try {
42+
switch (e.getStatus().getCode()) {
43+
case PERMISSION_DENIED:
44+
return new AccessDeniedException(e);
45+
case INTERNAL:
46+
return new InternalServiceException(e);
47+
case NOT_FOUND:
48+
if (detail.is(WorkflowExecutionAlreadyCompletedError.class)) {
49+
return new WorkflowExecutionAlreadyCompletedException(e);
50+
} else {
51+
return new EntityNotExistsException(e);
52+
}
53+
case ALREADY_EXISTS:
54+
if (detail.is(CancellationAlreadyRequestedError.class)) {
55+
return new CancellationAlreadyRequestedException(e);
56+
} else if (detail.is(DomainAlreadyExistsError.class)) {
57+
return new DomainAlreadyExistsException(e);
58+
} else if (detail.is(WorkflowExecutionAlreadyStartedError.class)) {
59+
WorkflowExecutionAlreadyStartedError error =
60+
detail.unpack(WorkflowExecutionAlreadyStartedError.class);
61+
return new WorkflowExecutionAlreadyStartedException(
62+
error.getStartRequestId(), error.getRunId());
63+
}
64+
case DATA_LOSS:
65+
return new InternalDataInconsistencyException(e);
66+
case FAILED_PRECONDITION:
67+
if (detail.is(ClientVersionNotSupportedError.class)) {
68+
ClientVersionNotSupportedError error =
69+
detail.unpack(ClientVersionNotSupportedError.class);
70+
return new ClientVersionNotSupportedException(
71+
error.getFeatureVersion(), error.getClientImpl(), error.getSupportedVersions());
72+
} else if (detail.is(FeatureNotEnabledError.class)) {
73+
FeatureNotEnabledError error = detail.unpack(FeatureNotEnabledError.class);
74+
return new FeatureNotEnabledException(error.getFeatureFlag());
75+
} else if (detail.is(DomainNotActiveError.class)) {
76+
DomainNotActiveError error = detail.unpack(DomainNotActiveError.class);
77+
return new DomainNotActiveException(
78+
error.getDomain(), error.getCurrentCluster(), error.getActiveCluster());
79+
}
80+
case RESOURCE_EXHAUSTED:
81+
if (detail.is(LimitExceededError.class)) {
82+
return new LimitExceededException(e);
83+
} else {
84+
return new ServiceBusyException(e);
85+
}
86+
case UNKNOWN:
87+
default:
88+
return new ServiceClientException(e);
89+
}
90+
} catch (InvalidProtocolBufferException ex) {
91+
return new ServiceClientException(ex);
6992
}
93+
}
7094
}
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
7+
* use this file except in compliance with the License. A copy of the License is
8+
* located at
9+
*
10+
* http://aws.amazon.com/apache2.0
11+
*
12+
* or in the "license" file accompanying this file. This file is distributed on
13+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
* express or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
118
package com.uber.cadence.serviceclient.exceptions;
219

320
public class AccessDeniedException extends ServiceClientException {
421

5-
public AccessDeniedException(Throwable cause) {
6-
super(cause);
7-
}
22+
public AccessDeniedException(Throwable cause) {
23+
super(cause);
24+
}
825
}
Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
7+
* use this file except in compliance with the License. A copy of the License is
8+
* located at
9+
*
10+
* http://aws.amazon.com/apache2.0
11+
*
12+
* or in the "license" file accompanying this file. This file is distributed on
13+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
* express or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
118
package com.uber.cadence.serviceclient.exceptions;
219

320
public class CancellationAlreadyRequestedException extends ServiceClientException {
4-
public CancellationAlreadyRequestedException(Throwable cause) {
5-
super(cause);
6-
}
7-
}
21+
public CancellationAlreadyRequestedException(Throwable cause) {
22+
super(cause);
23+
}
24+
}
Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
7+
* use this file except in compliance with the License. A copy of the License is
8+
* located at
9+
*
10+
* http://aws.amazon.com/apache2.0
11+
*
12+
* or in the "license" file accompanying this file. This file is distributed on
13+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
* express or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
118
package com.uber.cadence.serviceclient.exceptions;
219

320
public class ClientVersionNotSupportedException extends ServiceClientException {
4-
private final String featureVersion;
5-
private final String clientImpl;
6-
private final String supportedVersions;
21+
private final String featureVersion;
22+
private final String clientImpl;
23+
private final String supportedVersions;
724

8-
public ClientVersionNotSupportedException(String featureVersion, String clientImpl, String supportedVersions) {
9-
this.featureVersion = featureVersion;
10-
this.clientImpl = clientImpl;
11-
this.supportedVersions = supportedVersions;
12-
}
25+
public ClientVersionNotSupportedException(
26+
String featureVersion, String clientImpl, String supportedVersions) {
27+
this.featureVersion = featureVersion;
28+
this.clientImpl = clientImpl;
29+
this.supportedVersions = supportedVersions;
30+
}
1331

14-
public String getFeatureVersion() {
15-
return featureVersion;
16-
}
32+
public String getFeatureVersion() {
33+
return featureVersion;
34+
}
1735

18-
public String getClientImpl() {
19-
return clientImpl;
20-
}
36+
public String getClientImpl() {
37+
return clientImpl;
38+
}
2139

22-
public String getSupportedVersions() {
23-
return supportedVersions;
24-
}
25-
}
40+
public String getSupportedVersions() {
41+
return supportedVersions;
42+
}
43+
}
Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
7+
* use this file except in compliance with the License. A copy of the License is
8+
* located at
9+
*
10+
* http://aws.amazon.com/apache2.0
11+
*
12+
* or in the "license" file accompanying this file. This file is distributed on
13+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
* express or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
118
package com.uber.cadence.serviceclient.exceptions;
219

320
public class DomainAlreadyExistsException extends ServiceClientException {
4-
public DomainAlreadyExistsException(Throwable cause) {
5-
super(cause);
6-
}
7-
}
21+
public DomainAlreadyExistsException(Throwable cause) {
22+
super(cause);
23+
}
24+
}
Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,42 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
7+
* use this file except in compliance with the License. A copy of the License is
8+
* located at
9+
*
10+
* http://aws.amazon.com/apache2.0
11+
*
12+
* or in the "license" file accompanying this file. This file is distributed on
13+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
* express or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
118
package com.uber.cadence.serviceclient.exceptions;
219

320
public class DomainNotActiveException extends ServiceClientException {
4-
private final String domain;
5-
private final String currentCluster;
6-
private final String activeCluster;
21+
private final String domain;
22+
private final String currentCluster;
23+
private final String activeCluster;
724

8-
public DomainNotActiveException(String domain, String currentCluster, String activeCluster) {
9-
this.domain = domain;
10-
this.currentCluster = currentCluster;
11-
this.activeCluster = activeCluster;
12-
}
25+
public DomainNotActiveException(String domain, String currentCluster, String activeCluster) {
26+
this.domain = domain;
27+
this.currentCluster = currentCluster;
28+
this.activeCluster = activeCluster;
29+
}
1330

14-
public String getDomain() {
15-
return domain;
16-
}
31+
public String getDomain() {
32+
return domain;
33+
}
1734

18-
public String getCurrentCluster() {
19-
return currentCluster;
20-
}
35+
public String getCurrentCluster() {
36+
return currentCluster;
37+
}
2138

22-
public String getActiveCluster() {
23-
return activeCluster;
24-
}
25-
}
39+
public String getActiveCluster() {
40+
return activeCluster;
41+
}
42+
}
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
7+
* use this file except in compliance with the License. A copy of the License is
8+
* located at
9+
*
10+
* http://aws.amazon.com/apache2.0
11+
*
12+
* or in the "license" file accompanying this file. This file is distributed on
13+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
* express or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
118
package com.uber.cadence.serviceclient.exceptions;
219

320
public class EntityNotExistsException extends ServiceClientException {
421

5-
public EntityNotExistsException(Throwable cause) {
6-
super(cause);
7-
}
22+
public EntityNotExistsException(Throwable cause) {
23+
super(cause);
24+
}
825
}

0 commit comments

Comments
 (0)