Skip to content

Commit 8377269

Browse files
Copilotsophiatev
andauthored
Add unit tests for DurableTaskGrpcClientFactory (#257)
* Initial plan * Add unit tests for DurableTaskGrpcClientFactory and fix compilation error Co-authored-by: sophiatev <38052607+sophiatev@users.noreply.github.com> * Remove changes to DurableTaskGrpcClient.java and proto file, keep only test file Co-authored-by: sophiatev <38052607+sophiatev@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sophiatev <38052607+sophiatev@users.noreply.github.com>
1 parent 96e02b7 commit 8377269

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.durabletask;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
import static org.junit.jupiter.api.Assertions.*;
9+
10+
/**
11+
* Unit tests for DurableTaskGrpcClientFactory.
12+
*/
13+
public class DurableTaskGrpcClientFactoryTest {
14+
15+
@Test
16+
void getClient_samePort_returnsSameInstance() {
17+
// Arrange
18+
int port = 5001;
19+
20+
// Act
21+
DurableTaskClient client1 = DurableTaskGrpcClientFactory.getClient(port);
22+
DurableTaskClient client2 = DurableTaskGrpcClientFactory.getClient(port);
23+
24+
// Assert
25+
assertNotNull(client1, "First client should not be null");
26+
assertNotNull(client2, "Second client should not be null");
27+
assertSame(client1, client2, "getClient should return the same instance for the same port");
28+
}
29+
30+
@Test
31+
void getClient_differentPorts_returnsDifferentInstances() {
32+
// Arrange
33+
int port1 = 5002;
34+
int port2 = 5003;
35+
36+
// Act
37+
DurableTaskClient client1 = DurableTaskGrpcClientFactory.getClient(port1);
38+
DurableTaskClient client2 = DurableTaskGrpcClientFactory.getClient(port2);
39+
40+
// Assert
41+
assertNotNull(client1, "Client for port1 should not be null");
42+
assertNotNull(client2, "Client for port2 should not be null");
43+
assertNotSame(client1, client2, "getClient should return different instances for different ports");
44+
}
45+
46+
@Test
47+
void getClient_multiplePorts_maintainsCorrectMapping() {
48+
// Arrange
49+
int port1 = 5004;
50+
int port2 = 5005;
51+
int port3 = 5006;
52+
53+
// Act
54+
DurableTaskClient client1 = DurableTaskGrpcClientFactory.getClient(port1);
55+
DurableTaskClient client2 = DurableTaskGrpcClientFactory.getClient(port2);
56+
DurableTaskClient client3 = DurableTaskGrpcClientFactory.getClient(port3);
57+
58+
// Request the same ports again
59+
DurableTaskClient client1Again = DurableTaskGrpcClientFactory.getClient(port1);
60+
DurableTaskClient client2Again = DurableTaskGrpcClientFactory.getClient(port2);
61+
DurableTaskClient client3Again = DurableTaskGrpcClientFactory.getClient(port3);
62+
63+
// Assert
64+
// Verify each port returns the same instance
65+
assertSame(client1, client1Again, "Port " + port1 + " should return the same instance");
66+
assertSame(client2, client2Again, "Port " + port2 + " should return the same instance");
67+
assertSame(client3, client3Again, "Port " + port3 + " should return the same instance");
68+
69+
// Verify all instances are different from each other
70+
assertNotSame(client1, client2, "Client for port1 and port2 should be different");
71+
assertNotSame(client1, client3, "Client for port1 and port3 should be different");
72+
assertNotSame(client2, client3, "Client for port2 and port3 should be different");
73+
}
74+
}

0 commit comments

Comments
 (0)