Skip to content

Commit 918b1ec

Browse files
author
annie-mac
committed
fix tests
1 parent 38974a9 commit 918b1ec

File tree

2 files changed

+53
-25
lines changed

2 files changed

+53
-25
lines changed

sdk/cosmos/azure-cosmos-kafka-connect/src/test/java/com/azure/cosmos/kafka/connect/implementation/CosmosClientCacheConfigTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
public class CosmosClientCacheConfigTest {
1717

18-
@Test
18+
@Test(groups = "unit")
1919
void shouldBeEqualWhenAllValuesAreSame() {
2020
CosmosAadAuthConfig authConfig =
2121
new CosmosAadAuthConfig(
@@ -48,7 +48,7 @@ void shouldBeEqualWhenAllValuesAreSame() {
4848
.hasSameHashCodeAs(config2);
4949
}
5050

51-
@Test
51+
@Test(groups = "unit")
5252
void shouldNotBeEqualWhenValuesAreDifferent() {
5353
CosmosAadAuthConfig authConfig1 =
5454
new CosmosAadAuthConfig(
@@ -88,7 +88,7 @@ void shouldNotBeEqualWhenValuesAreDifferent() {
8888
.doesNotHaveSameHashCodeAs(config2);
8989
}
9090

91-
@Test
91+
@Test(groups = "unit")
9292
void shouldSerializeToStringCorrectly() {
9393
CosmosAadAuthConfig authConfig =
9494
new CosmosAadAuthConfig(
@@ -118,7 +118,7 @@ void shouldSerializeToStringCorrectly() {
118118
.contains("context1");
119119
}
120120

121-
@Test
121+
@Test(groups = "unit")
122122
void shouldHandleNullValuesCorrectly() {
123123
CosmosAadAuthConfig authConfig =
124124
new CosmosAadAuthConfig(
@@ -146,7 +146,7 @@ void shouldHandleNullValuesCorrectly() {
146146
.contains("||true||");
147147
}
148148

149-
@Test
149+
@Test(groups = "unit")
150150
void shouldNotBeEqualToNull() {
151151
CosmosAadAuthConfig authConfig =
152152
new CosmosAadAuthConfig(
@@ -168,7 +168,7 @@ void shouldNotBeEqualToNull() {
168168
assertThat(config).isNotNull();
169169
}
170170

171-
@Test
171+
@Test(groups = "unit")
172172
void shouldNotBeEqualToDifferentClass() {
173173
CosmosAadAuthConfig authConfig =
174174
new CosmosAadAuthConfig(

sdk/cosmos/azure-cosmos-kafka-connect/src/test/java/com/azure/cosmos/kafka/connect/implementation/CosmosClientCacheMetadataTest.java

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,53 @@
44
package com.azure.cosmos.kafka.connect.implementation;
55

66
import com.azure.cosmos.CosmosAsyncClient;
7-
import org.mockito.Mockito;
8-
import org.testng.annotations.BeforeMethod;
7+
import com.azure.cosmos.CosmosBridgeInternal;
8+
import com.azure.cosmos.CosmosClientBuilder;
9+
import com.azure.cosmos.implementation.RxDocumentClientImpl;
10+
import com.azure.cosmos.kafka.connect.KafkaCosmosTestConfigurations;
11+
import com.azure.cosmos.kafka.connect.KafkaCosmosTestSuiteBase;
12+
import org.testng.annotations.AfterClass;
13+
import org.testng.annotations.BeforeClass;
914
import org.testng.annotations.Test;
1015

1116
import java.time.Instant;
1217

1318
import static org.assertj.core.api.Assertions.assertThat;
14-
import static org.mockito.Mockito.verify;
1519

1620
/**
1721
* Test for CosmosClientCacheMetadata
1822
*/
19-
public class CosmosClientCacheMetadataTest {
20-
private CosmosAsyncClient mockClient;
21-
private Instant createdTime;
22-
private CosmosClientCacheMetadata metadata;
23+
public class CosmosClientCacheMetadataTest extends KafkaCosmosTestSuiteBase {
24+
private CosmosAsyncClient cosmosClient;
2325

24-
@BeforeMethod
26+
@BeforeClass(groups = "kafka-emulator")
2527
void setUp() {
26-
mockClient = Mockito.mock(CosmosAsyncClient.class);
27-
createdTime = Instant.now();
28-
metadata = new CosmosClientCacheMetadata(mockClient, createdTime);
28+
cosmosClient = new CosmosClientBuilder()
29+
.endpoint(KafkaCosmosTestConfigurations.HOST)
30+
.key(KafkaCosmosTestConfigurations.MASTER_KEY)
31+
.buildAsyncClient();
2932
}
3033

31-
@Test
34+
@AfterClass(groups = "kafka-emulator")
35+
void cleanup() {
36+
if (this.cosmosClient != null) {
37+
this.cosmosClient.close();
38+
}
39+
}
40+
41+
@Test(groups = "kafka-emulator")
3242
void shouldInitializeWithRefCountOne() {
43+
Instant createdTime = Instant.now();
44+
CosmosClientCacheMetadata metadata = new CosmosClientCacheMetadata(cosmosClient, createdTime);
45+
3346
assertThat(metadata.getRefCount()).isEqualTo(1);
3447
assertThat(metadata.getLastAccessed()).isEqualTo(createdTime);
3548
}
3649

37-
@Test
50+
@Test(groups = "kafka-emulator")
3851
void shouldIncrementRefCount() {
52+
CosmosClientCacheMetadata metadata = new CosmosClientCacheMetadata(cosmosClient, Instant.now());
53+
3954
long initialCount = metadata.getRefCount();
4055
metadata.incrementRefCount();
4156

@@ -44,8 +59,10 @@ void shouldIncrementRefCount() {
4459
.isEqualTo(2);
4560
}
4661

47-
@Test
62+
@Test(groups = "kafka-emulator")
4863
void shouldDecrementRefCount() {
64+
CosmosClientCacheMetadata metadata = new CosmosClientCacheMetadata(cosmosClient, Instant.now());
65+
4966
metadata.incrementRefCount(); // ref count = 2
5067
long countBeforeDecrement = metadata.getRefCount();
5168
metadata.decrementRefCount();
@@ -55,8 +72,10 @@ void shouldDecrementRefCount() {
5572
.isEqualTo(1);
5673
}
5774

58-
@Test
75+
@Test(groups = "kafka-emulator")
5976
void shouldUpdateLastAccessedTime() {
77+
CosmosClientCacheMetadata metadata = new CosmosClientCacheMetadata(cosmosClient, Instant.now());
78+
6079
Instant originalLastAccessed = metadata.getLastAccessed();
6180
// Sleep briefly to ensure time difference
6281
try {
@@ -72,14 +91,23 @@ void shouldUpdateLastAccessedTime() {
7291
.isNotEqualTo(originalLastAccessed);
7392
}
7493

75-
@Test
94+
@Test(groups = "kafka-emulator")
7695
void shouldReturnClient() {
77-
assertThat(metadata.getClient()).isSameAs(mockClient);
96+
CosmosClientCacheMetadata metadata = new CosmosClientCacheMetadata(cosmosClient, Instant.now());
97+
98+
assertThat(metadata.getClient()).isSameAs(cosmosClient);
7899
}
79100

80-
@Test
101+
@Test(groups = "kafka-emulator")
81102
void shouldCloseClientOnClose() {
103+
CosmosAsyncClient cosmosAsyncClient = new CosmosClientBuilder()
104+
.endpoint(KafkaCosmosTestConfigurations.HOST)
105+
.key(KafkaCosmosTestConfigurations.MASTER_KEY)
106+
.buildAsyncClient();
107+
CosmosClientCacheMetadata metadata = new CosmosClientCacheMetadata(cosmosAsyncClient, Instant.now());
82108
metadata.close();
83-
verify(mockClient).close();
109+
110+
assertThat(((RxDocumentClientImpl)CosmosBridgeInternal.getAsyncDocumentClient(cosmosAsyncClient)).isClosed())
111+
.isTrue();
84112
}
85113
}

0 commit comments

Comments
 (0)