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

Added tests for LocalActivityOptions #978

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
*
* * 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 com.uber.cadence.activity;

import static org.junit.Assert.assertEquals;

import com.uber.cadence.common.RetryOptions;
import java.time.Duration;
import java.util.Arrays;
import java.util.Collection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

// This test is separated into its own file because it uses the Parameterized runner
@RunWith(Parameterized.class)
public class LocalActivityOptionsEqualsTest {

private final LocalActivityOptions options1;
// In the java equals method the `other` parameter is of type Object
private final Object options2;
private final boolean equals;

public LocalActivityOptionsEqualsTest(
String name, LocalActivityOptions options1, Object options2, boolean equals) {
this.options1 = options1;
this.options2 = options2;
this.equals = equals;
}

@Parameterized.Parameters(name = "{index}: {0}")
public static Collection<Object[]> data() {
LocalActivityOptions options = LocalActivityOptionsTest.createOptions();

return Arrays.asList(
new Object[] {
"Same object", options, options, true,
},
new Object[] {
"Other is null", options, null, false,
},
new Object[] {
"Other is not instance of LocalActivityOptions", options, new Object(), false,
},
new Object[] {
"Emtpy equals empty",
new LocalActivityOptions.Builder().build(),
new LocalActivityOptions.Builder().build(),
true
},
new Object[] {
"Unset property on localActivityOptions is checked not equal",
new LocalActivityOptions.Builder().build(),
new LocalActivityOptions.Builder()
.setScheduleToCloseTimeout(Duration.ofSeconds(123))
.build(),
false
},
new Object[] {
"Property on localActivityOptions is checked equals",
new LocalActivityOptions.Builder()
.setScheduleToCloseTimeout(Duration.ofSeconds(123))
.build(),
new LocalActivityOptions.Builder()
.setScheduleToCloseTimeout(Duration.ofSeconds(123))
.build(),
true
},
new Object[] {
"Property on localActivityOptions is checked not equal",
new LocalActivityOptions.Builder()
.setScheduleToCloseTimeout(Duration.ofSeconds(1))
.build(),
new LocalActivityOptions.Builder()
.setScheduleToCloseTimeout(Duration.ofSeconds(2))
.build(),
false
},
new Object[] {
"retryOptions property not equal",
new LocalActivityOptions.Builder()
.setRetryOptions(
new RetryOptions.Builder().setInitialInterval(Duration.ofSeconds(1)).build())
.build(),
new LocalActivityOptions.Builder()
.setRetryOptions(
new RetryOptions.Builder().setInitialInterval(Duration.ofSeconds(2)).build())
.build(),
false
});
}

@Test
public void testEquals() {
boolean got = options1.equals(options2);
assertEquals(equals, got);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
*
* * 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 com.uber.cadence.activity;

import static org.junit.Assert.assertNotEquals;

import com.uber.cadence.common.RetryOptions;
import java.time.Duration;
import junit.framework.TestCase;
import org.junit.Test;

public class LocalActivityOptionsTest extends TestCase {

@Test
public void testTestToString() {
String asString = createOptions().toString();

final String expected =
"LocalActivityOptions{"
+ "scheduleToCloseTimeout=PT2M3S, "
Copy link
Member

Choose a reason for hiding this comment

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

I would expect it to be more human-readable, but that's OK as well :-)

+ "retryOptions=RetryOptions{"
+ "initialInterval=PT2M3S, "
+ "backoffCoefficient=0.0, "
+ "expiration=null, "
+ "maximumAttempts=43, "
+ "maximumInterval=null, "
+ "doNotRetry=null"
+ "}}";

assertEquals(expected, asString);
}

@Test
public void testTestHashCode() {
LocalActivityOptions options1 = createOptions(123);
LocalActivityOptions options2 = createOptions(456);

// The hash code of different objects should be different
assertNotEquals(options1.hashCode(), options2.hashCode());
}

public static LocalActivityOptions createOptions() {
return createOptions(123);
}

public static LocalActivityOptions createOptions(int initialRetryInterval) {
RetryOptions retryOptions =
new RetryOptions.Builder()
.setInitialInterval(Duration.ofSeconds(initialRetryInterval))
.setMaximumAttempts(43)
.build();

return new LocalActivityOptions.Builder()
.setScheduleToCloseTimeout(Duration.ofSeconds(123))
.setRetryOptions(retryOptions)
.build();
}
}