Skip to content

Commit c5b9700

Browse files
committed
test fixes
Signed-off-by: Attila Mészáros <[email protected]>
1 parent 7f3498c commit c5b9700

File tree

3 files changed

+120
-2
lines changed

3 files changed

+120
-2
lines changed

flink-kubernetes-operator/src/test/java/org/apache/flink/kubernetes/operator/reconciler/deployment/SessionReconcilerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void setup() {
7575
public void testStartSession() throws Exception {
7676
var count = new AtomicInteger(0);
7777
flinkService =
78-
new TestingFlinkService() {
78+
new TestingFlinkService(kubernetesClient) {
7979
@Override
8080
public void submitSessionCluster(Configuration conf) throws Exception {
8181
super.submitSessionCluster(conf);

flink-kubernetes-operator/src/test/java/org/apache/flink/kubernetes/operator/utils/IngressUtilsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class IngressUtilsTest {
5353

5454
private FlinkResourceContext<?> createResourceContext(FlinkDeployment appCluster) {
5555
// todo
56-
return new FlinkDeploymentContext(appCluster, null, null, null, null, null);
56+
return new FlinkDeploymentContext(
57+
appCluster, new TestingJosdkContext<>(client, Map.of()), null, null, null, null);
5758
}
5859

5960
@Test
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.flink.kubernetes.operator.utils;
20+
21+
import io.fabric8.kubernetes.api.model.HasMetadata;
22+
import io.fabric8.kubernetes.client.KubernetesClient;
23+
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
24+
import io.javaoperatorsdk.operator.api.reconciler.Context;
25+
import io.javaoperatorsdk.operator.api.reconciler.IndexedResourceCache;
26+
import io.javaoperatorsdk.operator.api.reconciler.RetryInfo;
27+
import io.javaoperatorsdk.operator.api.reconciler.dependent.managed.ManagedWorkflowAndDependentResourceContext;
28+
import io.javaoperatorsdk.operator.processing.event.EventSourceRetriever;
29+
30+
import java.util.List;
31+
import java.util.Map;
32+
import java.util.Optional;
33+
import java.util.Set;
34+
import java.util.concurrent.ExecutorService;
35+
36+
/**
37+
* JOSDK Context for unit testing.
38+
*
39+
* @param <P>
40+
*/
41+
public class TestingJosdkContext<P extends HasMetadata> implements Context<P> {
42+
43+
private final KubernetesClient kubernetesClient;
44+
private final Map<Class<?>, List<Object>> secondaryResources;
45+
46+
public TestingJosdkContext(
47+
KubernetesClient kubernetesClient, Map<Class<?>, List<Object>> secondaryResources) {
48+
this.kubernetesClient = kubernetesClient;
49+
this.secondaryResources = secondaryResources;
50+
}
51+
52+
@Override
53+
public Optional<RetryInfo> getRetryInfo() {
54+
return Optional.empty();
55+
}
56+
57+
@Override
58+
public <R> Set<R> getSecondaryResources(Class<R> expectedType) {
59+
var res = secondaryResources.get(expectedType);
60+
if (res == null) {
61+
return Set.of();
62+
}
63+
return (Set<R>) Set.of(res);
64+
}
65+
66+
@Override
67+
public <R> Optional<R> getSecondaryResource(Class<R> expectedType, String eventSourceName) {
68+
var resources = getSecondaryResources(expectedType);
69+
if (resources.isEmpty()) {
70+
return Optional.empty();
71+
} else if (resources.size() == 1) {
72+
return Optional.of(resources.iterator().next());
73+
} else {
74+
throw new IllegalStateException("Multiple secondary resources found: " + resources);
75+
}
76+
}
77+
78+
@Override
79+
public ControllerConfiguration<P> getControllerConfiguration() {
80+
return null;
81+
}
82+
83+
@Override
84+
public ManagedWorkflowAndDependentResourceContext managedWorkflowAndDependentResourceContext() {
85+
return null;
86+
}
87+
88+
@Override
89+
public EventSourceRetriever<P> eventSourceRetriever() {
90+
return null;
91+
}
92+
93+
@Override
94+
public KubernetesClient getClient() {
95+
return null;
96+
}
97+
98+
@Override
99+
public ExecutorService getWorkflowExecutorService() {
100+
return null;
101+
}
102+
103+
@Override
104+
public P getPrimaryResource() {
105+
return null;
106+
}
107+
108+
@Override
109+
public IndexedResourceCache<P> getPrimaryCache() {
110+
return null;
111+
}
112+
113+
@Override
114+
public boolean isNextReconciliationImminent() {
115+
return false;
116+
}
117+
}

0 commit comments

Comments
 (0)