|
12 | 12 | */ |
13 | 13 | package io.kubernetes.client.spring.extended.network; |
14 | 14 |
|
15 | | -import static org.junit.Assert.*; |
| 15 | +import static org.junit.Assert.assertEquals; |
| 16 | +import static org.junit.Assert.assertNotNull; |
| 17 | +import static org.junit.Assert.assertThrows; |
16 | 18 |
|
| 19 | +import io.kubernetes.client.extended.network.EndpointsLoadBalancer; |
17 | 20 | import io.kubernetes.client.extended.network.LoadBalanceStrategy; |
18 | 21 | import io.kubernetes.client.extended.network.LoadBalancer; |
| 22 | +import io.kubernetes.client.extended.network.RoundRobinLoadBalanceStrategy; |
19 | 23 | import io.kubernetes.client.extended.network.exception.NoAvailableAddressException; |
20 | 24 | import io.kubernetes.client.informer.cache.Cache; |
21 | 25 | import io.kubernetes.client.informer.cache.Lister; |
|
24 | 28 | import io.kubernetes.client.openapi.models.V1EndpointSubset; |
25 | 29 | import io.kubernetes.client.openapi.models.V1Endpoints; |
26 | 30 | import io.kubernetes.client.openapi.models.V1ObjectMeta; |
27 | | -import io.kubernetes.client.spring.extended.network.annotation.KubernetesEndpointsLoadBalanced; |
28 | 31 | import io.kubernetes.client.spring.extended.network.endpoints.EndpointsGetter; |
| 32 | +import io.kubernetes.client.spring.extended.network.endpoints.InformerEndpointsGetter; |
29 | 33 | import java.util.List; |
30 | 34 | import org.junit.Test; |
31 | 35 | import org.junit.runner.RunWith; |
@@ -53,28 +57,32 @@ public Lister<V1Endpoints> endpointsLister(Cache<V1Endpoints> endpointsCache) { |
53 | 57 | } |
54 | 58 |
|
55 | 59 | @Bean |
56 | | - public MyBean myBean() { |
57 | | - return new MyBean(); |
| 60 | + public MyBean myBean(Lister<V1Endpoints> lister) { |
| 61 | + return new MyBean(new MyEndpointGetter(), new MyStrategy(), lister); |
58 | 62 | } |
59 | 63 | } |
60 | 64 |
|
61 | 65 | static class MyBean { |
62 | | - @KubernetesEndpointsLoadBalanced(namespace = "default", name = "no-such") |
| 66 | + |
| 67 | + public MyBean( |
| 68 | + MyEndpointGetter myEndpointGetter, MyStrategy myStrategy, Lister<V1Endpoints> lister) { |
| 69 | + InformerEndpointsGetter getter = new InformerEndpointsGetter(lister); |
| 70 | + RoundRobinLoadBalanceStrategy strategy = new RoundRobinLoadBalanceStrategy(); |
| 71 | + noSuchLoadBalancer = |
| 72 | + new EndpointsLoadBalancer(() -> getter.get("default", "no-such"), strategy); |
| 73 | + fooLoadBalancer = new EndpointsLoadBalancer(() -> getter.get("default", "foo"), strategy); |
| 74 | + customStrategyLoadBalancer = |
| 75 | + new EndpointsLoadBalancer(() -> getter.get("default", "foo"), myStrategy); |
| 76 | + customEndpointGetterLoadBalancer = |
| 77 | + new EndpointsLoadBalancer(() -> myEndpointGetter.get("default", "foo"), strategy); |
| 78 | + } |
| 79 | + |
63 | 80 | private LoadBalancer noSuchLoadBalancer; |
64 | 81 |
|
65 | | - @KubernetesEndpointsLoadBalanced(namespace = "default", name = "foo") |
66 | 82 | private LoadBalancer fooLoadBalancer; |
67 | 83 |
|
68 | | - @KubernetesEndpointsLoadBalanced( |
69 | | - namespace = "default", |
70 | | - name = "foo", |
71 | | - strategy = MyStrategy.class) |
72 | 84 | private LoadBalancer customStrategyLoadBalancer; |
73 | 85 |
|
74 | | - @KubernetesEndpointsLoadBalanced( |
75 | | - namespace = "default", |
76 | | - name = "foo", |
77 | | - endpointsGetter = MyEndpointGetter.class) |
78 | 86 | private LoadBalancer customEndpointGetterLoadBalancer; |
79 | 87 | } |
80 | 88 |
|
@@ -109,6 +117,7 @@ public V1Endpoints get(String namespace, String name) { |
109 | 117 | new V1EndpointSubset() |
110 | 118 | .addAddressesItem(new V1EndpointAddress().ip("127.0.0.1")) |
111 | 119 | .addPortsItem(new V1EndpointPort().port(8080))); |
| 120 | + |
112 | 121 | @Autowired private MyBean myBean; |
113 | 122 |
|
114 | 123 | @Autowired private Cache<V1Endpoints> endpointsCache; |
|
0 commit comments