Skip to content

Commit cefff96

Browse files
committed
fixes java 16 compatibility
Signed-off-by: yue9944882 <291271447@qq.com>
1 parent e30312b commit cefff96

File tree

10 files changed

+45
-128
lines changed

10 files changed

+45
-128
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@
261261
<version>1.2.1</version>
262262
<scope>test</scope>
263263
</dependency>
264+
<dependency>
265+
<groupId>uk.org.webcompere</groupId>
266+
<artifactId>system-stubs-core</artifactId>
267+
<version>2.0.0</version>
268+
<scope>test</scope>
269+
</dependency>
264270
<dependency>
265271
<groupId>com.github.tomakehurst</groupId>
266272
<artifactId>wiremock</artifactId>

spring/pom.xml

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -109,50 +109,5 @@
109109
</plugin>
110110
</plugins>
111111
</build>
112-
<profiles>
113-
<profile>
114-
<id>surefire-newerJava</id>
115-
<activation>
116-
<jdk>(1.8,)</jdk>
117-
</activation>
118-
<build>
119-
<plugins>
120-
<plugin>
121-
<groupId>org.apache.maven.plugins</groupId>
122-
<artifactId>maven-surefire-plugin</artifactId>
123-
<configuration>
124-
<argLine>@{argLine} -Xms512m -Xmx1500m --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.time=ALL-UNNAMED</argLine>
125-
<parallel>methods</parallel>
126-
<perCoreThreadCount>false</perCoreThreadCount>
127-
<threadCount>1</threadCount>
128-
<forkCount>1</forkCount>
129-
<reuseForks>false</reuseForks>
130-
</configuration>
131-
</plugin>
132-
</plugins>
133-
</build>
134-
</profile>
135-
<profile>
136-
<id>surefire-java8</id>
137-
<activation>
138-
<jdk>1.8</jdk>
139-
</activation>
140-
<build>
141-
<plugins>
142-
<plugin>
143-
<groupId>org.apache.maven.plugins</groupId>
144-
<artifactId>maven-surefire-plugin</artifactId>
145-
<configuration>
146-
<argLine>@{argLine} -Xms512m -Xmx1500m</argLine>
147-
<parallel>methods</parallel>
148-
<perCoreThreadCount>false</perCoreThreadCount>
149-
<threadCount>1</threadCount>
150-
<forkCount>1</forkCount>
151-
<reuseForks>false</reuseForks>
152-
</configuration>
153-
</plugin>
154-
</plugins>
155-
</build>
156-
</profile>
157-
</profiles>
112+
158113
</project>

spring/src/test/java/io/kubernetes/client/spring/extended/controller/KubernetesInformerCreatorTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
import com.github.tomakehurst.wiremock.extension.PostServeAction;
2929
import com.github.tomakehurst.wiremock.junit.WireMockRule;
3030
import com.github.tomakehurst.wiremock.stubbing.ServeEvent;
31-
import com.google.gson.Gson;
3231
import io.kubernetes.client.informer.SharedIndexInformer;
3332
import io.kubernetes.client.informer.SharedInformerFactory;
3433
import io.kubernetes.client.informer.cache.Lister;
3534
import io.kubernetes.client.openapi.ApiClient;
35+
import io.kubernetes.client.openapi.JSON;
3636
import io.kubernetes.client.openapi.models.V1ConfigMap;
3737
import io.kubernetes.client.openapi.models.V1ConfigMapList;
3838
import io.kubernetes.client.openapi.models.V1ListMeta;
@@ -135,8 +135,8 @@ public void testInformerInjection() throws InterruptedException {
135135
aResponse()
136136
.withStatus(200)
137137
.withBody(
138-
new Gson()
139-
.toJson(
138+
new JSON()
139+
.serialize(
140140
new V1PodList()
141141
.metadata(new V1ListMeta().resourceVersion("0"))
142142
.items(Arrays.asList(foo1))))));
@@ -154,8 +154,8 @@ public void testInformerInjection() throws InterruptedException {
154154
aResponse()
155155
.withStatus(200)
156156
.withBody(
157-
new Gson()
158-
.toJson(
157+
new JSON()
158+
.serialize(
159159
new V1ConfigMapList()
160160
.metadata(new V1ListMeta().resourceVersion("0"))
161161
.items(Arrays.asList(bar1))))));

util/pom.xml

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@
101101
<scope>test</scope>
102102
</dependency>
103103
<dependency>
104-
<groupId>com.github.stefanbirkner</groupId>
105-
<artifactId>system-lambda</artifactId>
104+
<groupId>uk.org.webcompere</groupId>
105+
<artifactId>system-stubs-core</artifactId>
106106
<scope>test</scope>
107107
</dependency>
108108
<dependency>
@@ -159,52 +159,4 @@
159159
</plugin>
160160
</plugins>
161161
</build>
162-
<profiles>
163-
<profile>
164-
<id>surefire-newerJava</id>
165-
<activation>
166-
<jdk>(1.8,)</jdk>
167-
</activation>
168-
<build>
169-
<plugins>
170-
<plugin>
171-
<groupId>org.apache.maven.plugins</groupId>
172-
<artifactId>maven-surefire-plugin</artifactId>
173-
<configuration>
174-
<argLine>
175-
@{argLine} -Xms512m -Xmx1500m --illegal-access=warn --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.time=ALL-UNNAMED
176-
</argLine>
177-
<parallel>methods</parallel>
178-
<perCoreThreadCount>false</perCoreThreadCount>
179-
<threadCount>1</threadCount>
180-
<forkCount>1</forkCount>
181-
<reuseForks>false</reuseForks>
182-
</configuration>
183-
</plugin>
184-
</plugins>
185-
</build>
186-
</profile>
187-
<profile>
188-
<id>surefire-java8</id>
189-
<activation>
190-
<jdk>1.8</jdk>
191-
</activation>
192-
<build>
193-
<plugins>
194-
<plugin>
195-
<groupId>org.apache.maven.plugins</groupId>
196-
<artifactId>maven-surefire-plugin</artifactId>
197-
<configuration>
198-
<argLine>@{argLine} -Xms512m -Xmx1500m</argLine>
199-
<parallel>methods</parallel>
200-
<perCoreThreadCount>false</perCoreThreadCount>
201-
<threadCount>1</threadCount>
202-
<forkCount>1</forkCount>
203-
<reuseForks>false</reuseForks>
204-
</configuration>
205-
</plugin>
206-
</plugins>
207-
</build>
208-
</profile>
209-
</profiles>
210162
</project>

util/src/main/java/io/kubernetes/client/util/Watch.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public static class Response<T> {
5252

5353
public V1Status status;
5454

55+
public Response() {}
56+
5557
public Response(String type, T object) {
5658
this.type = type;
5759
this.object = object;

util/src/test/java/io/kubernetes/client/util/ClientBuilderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*/
1313
package io.kubernetes.client.util;
1414

15-
import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable;
1615
import static io.kubernetes.client.util.Config.ENV_SERVICE_HOST;
1716
import static io.kubernetes.client.util.Config.ENV_SERVICE_PORT;
1817
import static org.hamcrest.MatcherAssert.assertThat;
@@ -21,6 +20,7 @@
2120
import static org.junit.Assert.assertThrows;
2221
import static org.mockito.Mockito.mock;
2322
import static org.mockito.Mockito.verify;
23+
import static uk.org.webcompere.systemstubs.SystemStubs.withEnvironmentVariable;
2424

2525
import io.kubernetes.client.Resources;
2626
import io.kubernetes.client.openapi.ApiClient;

util/src/test/java/io/kubernetes/client/util/ConfigTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
*/
1313
package io.kubernetes.client.util;
1414

15-
import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable;
1615
import static org.junit.Assert.*;
16+
import static uk.org.webcompere.systemstubs.SystemStubs.withEnvironmentVariable;
1717

1818
import io.kubernetes.client.openapi.ApiClient;
1919
import java.io.File;

util/src/test/java/io/kubernetes/client/util/generic/GenericKubernetesApiForCoreApiTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
import static org.junit.Assert.*;
1717

1818
import com.github.tomakehurst.wiremock.junit.WireMockRule;
19-
import com.google.gson.Gson;
2019
import io.kubernetes.client.custom.V1Patch;
2120
import io.kubernetes.client.openapi.ApiClient;
21+
import io.kubernetes.client.openapi.JSON;
2222
import io.kubernetes.client.openapi.models.V1ListMeta;
2323
import io.kubernetes.client.openapi.models.V1ObjectMeta;
2424
import io.kubernetes.client.openapi.models.V1Pod;
@@ -36,6 +36,7 @@ public class GenericKubernetesApiForCoreApiTest {
3636

3737
@Rule public WireMockRule wireMockRule = new WireMockRule(8181);
3838

39+
private JSON json = new JSON();
3940
private GenericKubernetesApi<V1Pod, V1PodList> podClient;
4041

4142
@Before
@@ -51,7 +52,7 @@ public void deleteNamespacedPodReturningStatus() {
5152
V1Status status = new V1Status().kind("Status").code(200).message("good!");
5253
stubFor(
5354
delete(urlEqualTo("/api/v1/namespaces/default/pods/foo1"))
54-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(status))));
55+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(status))));
5556

5657
KubernetesApiResponse<V1Pod> deletePodResp = podClient.delete("default", "foo1", null);
5758
assertTrue(deletePodResp.isSuccess());
@@ -67,7 +68,7 @@ public void deleteNamespacedPodReturningDeletedObject() {
6768

6869
stubFor(
6970
delete(urlEqualTo("/api/v1/namespaces/default/pods/foo1"))
70-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(foo1))));
71+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
7172

7273
KubernetesApiResponse<V1Pod> deletePodResp = podClient.delete("default", "foo1");
7374
assertTrue(deletePodResp.isSuccess());
@@ -82,7 +83,7 @@ public void deleteNamespacedPodReturningForbiddenStatus() {
8283

8384
stubFor(
8485
delete(urlEqualTo("/api/v1/namespaces/default/pods/foo1"))
85-
.willReturn(aResponse().withStatus(403).withBody(new Gson().toJson(status))));
86+
.willReturn(aResponse().withStatus(403).withBody(json.serialize(status))));
8687

8788
KubernetesApiResponse<V1Pod> deletePodResp = podClient.delete("default", "foo1");
8889
assertFalse(deletePodResp.isSuccess());
@@ -97,7 +98,7 @@ public void listNamespacedPodReturningObject() {
9798

9899
stubFor(
99100
get(urlPathEqualTo("/api/v1/namespaces/default/pods"))
100-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(podList))));
101+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(podList))));
101102
KubernetesApiResponse<V1PodList> podListResp = podClient.list("default");
102103
assertTrue(podListResp.isSuccess());
103104
assertEquals(podList, podListResp.getObject());
@@ -111,7 +112,7 @@ public void listClusterPodReturningObject() {
111112

112113
stubFor(
113114
get(urlPathEqualTo("/api/v1/pods"))
114-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(podList))));
115+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(podList))));
115116
KubernetesApiResponse<V1PodList> podListResp = podClient.list();
116117
assertTrue(podListResp.isSuccess());
117118
assertEquals(podList, podListResp.getObject());
@@ -128,7 +129,7 @@ public void createNamespacedPodReturningObject() {
128129

129130
stubFor(
130131
post(urlEqualTo("/api/v1/namespaces/default/pods"))
131-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(foo1))));
132+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
132133
KubernetesApiResponse<V1Pod> podListResp = podClient.create(foo1);
133134
assertTrue(podListResp.isSuccess());
134135
assertEquals(foo1, podListResp.getObject());
@@ -143,7 +144,7 @@ public void updateNamespacedPodReturningObject() {
143144

144145
stubFor(
145146
put(urlEqualTo("/api/v1/namespaces/default/pods/foo1"))
146-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(foo1))));
147+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
147148
KubernetesApiResponse<V1Pod> podListResp = podClient.update(foo1);
148149
assertTrue(podListResp.isSuccess());
149150
assertEquals(foo1, podListResp.getObject());
@@ -159,7 +160,7 @@ public void patchNamespacedPodReturningObject() {
159160
stubFor(
160161
patch(urlEqualTo("/api/v1/namespaces/default/pods/foo1"))
161162
.withHeader("Content-Type", containing(V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH))
162-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(foo1))));
163+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
163164
KubernetesApiResponse<V1Pod> podPatchResp =
164165
podClient.patch("default", "foo1", V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, v1Patch);
165166

@@ -179,7 +180,7 @@ public void patchNamespacedPodWithApiPrefix() {
179180
stubFor(
180181
patch(urlEqualTo(prefix + "/api/v1/namespaces/default/pods/foo1"))
181182
.withHeader("Content-Type", containing(V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH))
182-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(foo1))));
183+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
183184

184185
GenericKubernetesApi<V1Pod, V1PodList> rancherPodClient =
185186
new GenericKubernetesApi<>(

util/src/test/java/io/kubernetes/client/util/generic/GenericKubernetesApiTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import static org.junit.Assert.*;
1717

1818
import com.github.tomakehurst.wiremock.junit.WireMockRule;
19-
import com.google.gson.Gson;
2019
import io.kubernetes.client.custom.V1Patch;
2120
import io.kubernetes.client.openapi.ApiClient;
2221
import io.kubernetes.client.openapi.ApiException;
@@ -41,6 +40,7 @@ public class GenericKubernetesApiTest {
4140

4241
@Rule public WireMockRule wireMockRule = new WireMockRule(8181);
4342

43+
private JSON json = new JSON();
4444
private GenericKubernetesApi<V1Job, V1JobList> jobClient;
4545

4646
@Before
@@ -56,7 +56,7 @@ public void deleteNamespacedJobReturningStatus() {
5656
V1Status status = new V1Status().kind("Status").code(200).message("good!");
5757
stubFor(
5858
delete(urlEqualTo("/apis/batch/v1/namespaces/default/jobs/foo1"))
59-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(status))));
59+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(status))));
6060

6161
KubernetesApiResponse<V1Job> deleteJobResp = jobClient.delete("default", "foo1", null);
6262
assertTrue(deleteJobResp.isSuccess());
@@ -72,7 +72,7 @@ public void deleteNamespacedJobReturningDeletedObject() {
7272

7373
stubFor(
7474
delete(urlEqualTo("/apis/batch/v1/namespaces/default/jobs/foo1"))
75-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(foo1))));
75+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
7676

7777
KubernetesApiResponse<V1Job> deleteJobResp = jobClient.delete("default", "foo1");
7878
assertTrue(deleteJobResp.isSuccess());
@@ -87,7 +87,7 @@ public void deleteNamespacedJobReturningForbiddenStatus() {
8787

8888
stubFor(
8989
delete(urlEqualTo("/apis/batch/v1/namespaces/default/jobs/foo1"))
90-
.willReturn(aResponse().withStatus(403).withBody(new Gson().toJson(status))));
90+
.willReturn(aResponse().withStatus(403).withBody(json.serialize(status))));
9191

9292
KubernetesApiResponse<V1Job> deleteJobResp = jobClient.delete("default", "foo1");
9393
assertFalse(deleteJobResp.isSuccess());
@@ -102,7 +102,7 @@ public void listNamespacedJobReturningObject() {
102102

103103
stubFor(
104104
get(urlPathEqualTo("/apis/batch/v1/namespaces/default/jobs"))
105-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(jobList))));
105+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(jobList))));
106106
KubernetesApiResponse<V1JobList> jobListResp = jobClient.list("default");
107107
assertTrue(jobListResp.isSuccess());
108108
assertEquals(jobList, jobListResp.getObject());
@@ -116,7 +116,7 @@ public void listClusterJobReturningObject() {
116116

117117
stubFor(
118118
get(urlPathEqualTo("/apis/batch/v1/jobs"))
119-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(jobList))));
119+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(jobList))));
120120
KubernetesApiResponse<V1JobList> jobListResp = jobClient.list();
121121
assertTrue(jobListResp.isSuccess());
122122
assertEquals(jobList, jobListResp.getObject());
@@ -131,7 +131,7 @@ public void createNamespacedJobReturningObject() {
131131

132132
stubFor(
133133
post(urlEqualTo("/apis/batch/v1/namespaces/default/jobs"))
134-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(foo1))));
134+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
135135
KubernetesApiResponse<V1Job> jobListResp = jobClient.create(foo1);
136136
assertTrue(jobListResp.isSuccess());
137137
assertEquals(foo1, jobListResp.getObject());
@@ -146,7 +146,7 @@ public void updateNamespacedJobReturningObject() {
146146

147147
stubFor(
148148
put(urlEqualTo("/apis/batch/v1/namespaces/default/jobs/foo1"))
149-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(foo1))));
149+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
150150
KubernetesApiResponse<V1Job> jobListResp = jobClient.update(foo1);
151151
assertTrue(jobListResp.isSuccess());
152152
assertEquals(foo1, jobListResp.getObject());
@@ -179,7 +179,7 @@ public void patchNamespacedJobReturningObject() {
179179
stubFor(
180180
patch(urlEqualTo("/apis/batch/v1/namespaces/default/jobs/foo1"))
181181
.withHeader("Content-Type", containing(V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH))
182-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(foo1))));
182+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
183183
KubernetesApiResponse<V1Job> jobPatchResp =
184184
jobClient.patch("default", "foo1", V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, v1Patch);
185185

@@ -195,7 +195,7 @@ public void watchNamespacedJobReturningObject() throws ApiException {
195195

196196
stubFor(
197197
get(urlPathEqualTo("/apis/batch/v1/namespaces/default/jobs"))
198-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(jobList))));
198+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(jobList))));
199199
Watchable<V1Job> jobListWatch = jobClient.watch("default", new ListOptions());
200200
verify(
201201
1,

0 commit comments

Comments
 (0)