forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Varun Bansal <bansvaru@amazon.com>
- Loading branch information
Showing
3 changed files
with
121 additions
and
0 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
53 changes: 53 additions & 0 deletions
53
libs/task-commons/src/test/java/org/opensearch/task/commons/task/TaskIdTests.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,53 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.task.commons.task; | ||
|
||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
/** | ||
* Tests for {@link TaskId} | ||
*/ | ||
public class TaskIdTests extends OpenSearchTestCase { | ||
|
||
public void testConstructorAndGetValue() { | ||
TaskId taskId = new TaskId("123"); | ||
assertEquals("123", taskId.getValue()); | ||
} | ||
|
||
public void testEqualsWithSameId() { | ||
TaskId taskId1 = new TaskId("456"); | ||
TaskId taskId2 = new TaskId("456"); | ||
assertEquals(taskId1, taskId2); | ||
} | ||
|
||
public void testEqualsWithDifferentId() { | ||
TaskId taskId1 = new TaskId("789"); | ||
TaskId taskId2 = new TaskId("987"); | ||
assertNotEquals(taskId1, taskId2); | ||
} | ||
|
||
public void testEqualsWithNull() { | ||
TaskId taskId = new TaskId("abc"); | ||
assertNotEquals(null, taskId); | ||
} | ||
|
||
public void testEqualsWithDifferentClass() { | ||
TaskId taskId = new TaskId("def"); | ||
assertNotEquals(taskId, new Object()); | ||
} | ||
|
||
public void testHashCode() { | ||
TaskId taskId1 = new TaskId("456"); | ||
TaskId taskId2 = new TaskId("456"); | ||
assertEquals(taskId1.hashCode(), taskId2.hashCode()); | ||
|
||
TaskId taskId3 = new TaskId("4567"); | ||
assertNotEquals(taskId1.hashCode(), taskId3.hashCode()); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
libs/task-commons/src/test/java/org/opensearch/task/commons/worker/WorkerNodeTests.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,52 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.task.commons.worker; | ||
|
||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
/** | ||
* Tests for {@link WorkerNode} | ||
*/ | ||
public class WorkerNodeTests extends OpenSearchTestCase { | ||
|
||
public void testCreateWorkerNode() { | ||
WorkerNode worker = WorkerNode.createWorkerNode("1", "Worker1", "192.168.1.1"); | ||
assertNotNull(worker); | ||
assertEquals("1", worker.getId()); | ||
assertEquals("Worker1", worker.getName()); | ||
assertEquals("192.168.1.1", worker.getIp()); | ||
} | ||
|
||
public void testEquality() { | ||
WorkerNode worker1 = WorkerNode.createWorkerNode("5", "Worker5", "192.168.1.5"); | ||
WorkerNode worker2 = WorkerNode.createWorkerNode("5", "Worker5", "192.168.1.5"); | ||
WorkerNode worker3 = WorkerNode.createWorkerNode("6", "Worker6", "192.168.1.6"); | ||
|
||
assertEquals(worker1, worker2); | ||
assertNotEquals(worker1, worker3); | ||
assertNotEquals(worker2, worker3); | ||
} | ||
|
||
public void testHashCode() { | ||
WorkerNode worker1 = WorkerNode.createWorkerNode("7", "Worker7", "192.168.1.7"); | ||
WorkerNode worker2 = WorkerNode.createWorkerNode("7", "Worker7", "192.168.1.7"); | ||
|
||
assertEquals(worker1.hashCode(), worker2.hashCode()); | ||
} | ||
|
||
public void testNotEqualToNull() { | ||
WorkerNode worker = WorkerNode.createWorkerNode("8", "Worker8", "192.168.1.8"); | ||
assertNotEquals(null, worker); | ||
} | ||
|
||
public void testNotEqualToDifferentClass() { | ||
WorkerNode worker = WorkerNode.createWorkerNode("9", "Worker9", "192.168.1.9"); | ||
assertNotEquals(worker, new Object()); | ||
} | ||
} |