Skip to content

Commit eec87c1

Browse files
committed
[WIP] add test
Signed-off-by: jkalinic <[email protected]>
1 parent 895b540 commit eec87c1

File tree

4 files changed

+147
-18
lines changed

4 files changed

+147
-18
lines changed

systemtests/src/main/java/com/github/streamshub/systemtests/locators/NodesPageSelectors.java

Lines changed: 82 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,7 @@ private NodesPageSelectors() {}
8888
public static final String NPS_REBALANCE_PROPOSAL_DROPDOWN_BUTTON = new CssBuilder(NPS_REBALANCE_TABLE_ITEMS)
8989
.withChild()
9090
.withElementTd().withComponentTable().withSubComponentTd().nth(1).withChild()
91-
.withElementButton().withComponentButton().withChild()
92-
.build();
93-
94-
public static final String NPS_REBALANCE_PROPOSAL_STATUS = new CssBuilder(NPS_REBALANCE_TABLE_ITEMS)
95-
.withChild()
96-
.withElementTd().withComponentTable().withSubComponentTd().nth(3).withChild()
97-
.withElementDiv().withChild()
98-
.withElementSpan()
91+
.withElementButton().withComponentButton()
9992
.build();
10093

10194
public static final String NPS_REBALANCE_PROPOSAL_STATUS = new CssBuilder(NPS_REBALANCE_TABLE_ITEMS)
@@ -134,11 +127,91 @@ private NodesPageSelectors() {}
134127
.withElementDiv().withComponentDescriptionList().withSubComponentText()
135128
.build();
136129

137-
public static final String NPS_REBALANCE_PROPOSAL_DROPDOWN_APPROVAL = new CssBuilder(NPS_REBALANCE_PROPOSAL_DROPDOWN_ITEMS)
130+
public static final String NPS_REBALANCE_PROPOSAL_DROPDOWN_AUTO_APPROVAL_ENABLED = new CssBuilder(NPS_REBALANCE_PROPOSAL_DROPDOWN_ITEMS)
138131
.withChild()
139132
.withElementDiv().nth(1).withChild()
140133
.withElementDiv().withComponentDescriptionList().withSubComponentGroup().withChild()
141134
.withElementDd().withComponentDescriptionList().withSubComponentDescription().withChild()
142135
.withElementDiv().withComponentDescriptionList().withSubComponentText()
143136
.build();
137+
138+
public static final String NPS_PROPOSAL_ACTION_DROPDOWN_BUTTON = new CssBuilder(NPS_REBALANCE_TABLE_ITEMS)
139+
.withChild()
140+
.withElementTd().withComponentTable().withSubComponentTd().nth(5).withChild()
141+
.withElementButton().withComponentMenuToggle()
142+
.build();
143+
144+
145+
public static final String NPS_PROPOSAL_ACTION_DROPDOWN_ITEMS = new CssBuilder(CssSelectors.PAGES_CONTENT)
146+
.withChild()
147+
.withElementDiv().withComponentPage().withSubComponentMainBody().withChild()
148+
.withElementDiv().withLayoutGrid().withChild()
149+
.withElementDiv().withLayoutGrid().withSubComponentItem().nth(3).withChild()
150+
.withElementDiv().withComponentScrollOuterWrapper().withChild()
151+
.withElementDiv().withComponentMenu().withChild()
152+
.withElementDiv().withComponentMenu().withSubComponentContent().withChild()
153+
.withElementUl().withComponentMenu().withSubComponentList().withChild()
154+
.withElementLi().withComponentMenu().withSubComponentListItem()
155+
.build();
156+
157+
public static final String NPS_PROPOSAL_ACTION_APPROVE_BUTTON = new CssBuilder(NPS_PROPOSAL_ACTION_DROPDOWN_ITEMS)
158+
.nth(1)
159+
.build();
160+
161+
public static final String NPS_PROPOSAL_ACTION_REFRESH_BUTTON = new CssBuilder(NPS_PROPOSAL_ACTION_DROPDOWN_ITEMS)
162+
.nth(2)
163+
.build();
164+
165+
public static final String NPS_PROPOSAL_ACTION_STOP_BUTTON = new CssBuilder(NPS_PROPOSAL_ACTION_DROPDOWN_ITEMS)
166+
.nth(3)
167+
.build();
168+
169+
170+
public static final String NPS_PROPOSAL_MODAL_DATA_TO_MOVE = new CssBuilder(CssSelectors.PAGES_POPUP_MODAL_BODY)
171+
.withChild()
172+
.withElementDl().withComponentDescriptionList().withChild()
173+
.withElementDiv().withComponentDescriptionList().withSubComponentGroup().nth(1).withChild()
174+
.withElementDd().withComponentDescriptionList().withSubComponentDescription().withChild()
175+
.withElementDiv().withComponentDescriptionList().withSubComponentText()
176+
.build();
177+
178+
public static final String NPS_PROPOSAL_MODAL_DATA_MONITORED_PARTITIONS_PERCENTAGE = new CssBuilder(CssSelectors.PAGES_POPUP_MODAL_BODY)
179+
.withChild()
180+
.withElementDl().withComponentDescriptionList().withChild()
181+
.withElementDiv().withComponentDescriptionList().withSubComponentGroup().nth(6).withChild()
182+
.withElementDd().withComponentDescriptionList().withSubComponentDescription().withChild()
183+
.withElementDiv().withComponentDescriptionList().withSubComponentText()
184+
.build();
185+
186+
public static final String NPS_PROPOSAL_MODAL_DATA_NUMBER_REPLICA_MOVEMENTS = new CssBuilder(CssSelectors.PAGES_POPUP_MODAL_BODY)
187+
.withChild()
188+
.withElementDl().withComponentDescriptionList().withChild()
189+
.withElementDiv().withComponentDescriptionList().withSubComponentGroup().nth(9).withChild()
190+
.withElementDd().withComponentDescriptionList().withSubComponentDescription().withChild()
191+
.withElementDiv().withComponentDescriptionList().withSubComponentText()
192+
.build();
193+
194+
public static final String NPS_PROPOSAL_MODAL_DATA_BALANCEDNESS_AFTER = new CssBuilder(CssSelectors.PAGES_POPUP_MODAL_BODY)
195+
.withChild()
196+
.withElementDl().withComponentDescriptionList().withChild()
197+
.withElementDiv().withComponentDescriptionList().withSubComponentGroup().nth(10).withChild()
198+
.withElementDd().withComponentDescriptionList().withSubComponentDescription().withChild()
199+
.withElementDiv().withComponentDescriptionList().withSubComponentText()
200+
.build();
201+
202+
public static final String NPS_PROPOSAL_MODAL_DATA_BALANCEDNESS_BEFORE = new CssBuilder(CssSelectors.PAGES_POPUP_MODAL_BODY)
203+
.withChild()
204+
.withElementDl().withComponentDescriptionList().withChild()
205+
.withElementDiv().withComponentDescriptionList().withSubComponentGroup().nth(11).withChild()
206+
.withElementDd().withComponentDescriptionList().withSubComponentDescription().withChild()
207+
.withElementDiv().withComponentDescriptionList().withSubComponentText()
208+
.build();
209+
210+
public static final String NPS_PROPOSAL_MODAL_CLOSE_BUTTON = new CssBuilder(CssSelectors.PAGES_POPUP_MODAL)
211+
.withChild()
212+
.withElementFooter().withComponentModalBox().withSubComponentFooter().withChild()
213+
.withElementButton().withComponentButton()
214+
.build();
215+
216+
public static final String NPS_PROPOSAL_MODAL_CONFIRM_BUTTON = CssSelectors.PAGES_MODAL_CONFIRM_BUTTON;
144217
}

systemtests/src/main/java/com/github/streamshub/systemtests/setup/strimzi/KafkaSetup.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,13 @@ public static KafkaBuilder getKafkaWithCc(String namespaceName, String clusterNa
347347
}
348348

349349

350-
public static KafkaRebalanceBuilder getKafkaRebalance(String namespace, String clusterName) {
350+
public static KafkaRebalanceBuilder getKafkaRebalance(String namespace, String clusterName, String rebalanceName) {
351351
return new KafkaRebalanceBuilder()
352352
.withApiVersion(Constants.STRIMZI_API_V1)
353353
.withNewMetadata()
354354
.addToLabels(ResourceLabels.STRIMZI_CLUSTER_LABEL, clusterName)
355355
.withNamespace(namespace)
356-
.withName(namespace)
356+
.withName(rebalanceName)
357357
.endMetadata()
358358
.withNewSpec()
359359
.endSpec();

systemtests/src/main/java/com/github/streamshub/systemtests/utils/WaitUtils.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import io.skodjob.testframe.wait.Wait;
2525
import io.strimzi.api.kafka.model.kafka.Kafka;
2626
import io.strimzi.api.kafka.model.nodepool.KafkaNodePool;
27+
import io.strimzi.api.kafka.model.rebalance.KafkaRebalance;
28+
import io.strimzi.api.kafka.model.rebalance.KafkaRebalanceState;
2729
import io.strimzi.api.kafka.model.topic.KafkaTopic;
2830
import org.apache.logging.log4j.Logger;
2931

@@ -505,4 +507,18 @@ public static void waitForLogInPod(String namespace, String podName, String expe
505507
return KubeResourceManager.get().kubeClient().getLogsFromPod(namespace, podName).contains(expectedLog);
506508
});
507509
}
510+
511+
public static void waitForKafkaRebalanceProposalStatus(String namespace, String rebalanceName, KafkaRebalanceState kafkaRebalanceState) {
512+
Wait.until(String.format("KafkaRabalance %s/%s to be in state [%s]", namespace, rebalanceName, kafkaRebalanceState),
513+
TestFrameConstants.GLOBAL_POLL_INTERVAL_MEDIUM, TestFrameConstants.GLOBAL_TIMEOUT_MEDIUM,
514+
() -> {
515+
KafkaRebalance rebalance = ResourceUtils.getKubeResource(KafkaRebalance.class, namespace, rebalanceName);
516+
return rebalance != null && rebalance.getStatus() != null &&
517+
rebalance.getStatus().getConditions().stream()
518+
.filter(c -> c.getType().equals(kafkaRebalanceState.name()))
519+
.map(c -> c.getStatus().equals("True"))
520+
.findFirst()
521+
.orElse(false);
522+
});
523+
}
508524
}

systemtests/src/test/java/com/github/streamshub/systemtests/kafka/RebalanceST.java

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,31 @@
22

33
import com.github.streamshub.systemtests.AbstractST;
44
import com.github.streamshub.systemtests.TestCaseConfig;
5-
import com.github.streamshub.systemtests.constants.Constants;
65
import com.github.streamshub.systemtests.constants.TestTags;
7-
import com.github.streamshub.systemtests.locators.CssBuilder;
86
import com.github.streamshub.systemtests.locators.NodesPageSelectors;
97
import com.github.streamshub.systemtests.logs.LogWrapper;
108
import com.github.streamshub.systemtests.setup.console.ConsoleInstanceSetup;
119
import com.github.streamshub.systemtests.setup.strimzi.KafkaSetup;
10+
import com.github.streamshub.systemtests.utils.WaitUtils;
1211
import com.github.streamshub.systemtests.utils.playwright.PwPageUrls;
1312
import com.github.streamshub.systemtests.utils.playwright.PwUtils;
1413
import com.github.streamshub.systemtests.utils.resourceutils.KafkaTopicUtils;
14+
import com.github.streamshub.systemtests.utils.resourceutils.KafkaUtils;
1515
import com.github.streamshub.systemtests.utils.resourceutils.NamespaceUtils;
16+
import com.github.streamshub.systemtests.utils.resourceutils.ResourceUtils;
1617
import io.skodjob.testframe.resources.KubeResourceManager;
18+
import io.strimzi.api.kafka.model.rebalance.KafkaRebalance;
19+
import io.strimzi.api.kafka.model.rebalance.KafkaRebalanceMode;
20+
import io.strimzi.api.kafka.model.rebalance.KafkaRebalanceState;
1721
import org.apache.logging.log4j.Logger;
1822
import org.junit.jupiter.api.AfterEach;
1923
import org.junit.jupiter.api.BeforeEach;
2024
import org.junit.jupiter.api.Tag;
2125
import org.junit.jupiter.api.Test;
2226

27+
import java.util.Locale;
28+
import java.util.Map;
29+
2330
import static com.github.streamshub.systemtests.utils.Utils.getTestCaseConfig;
2431
import static org.junit.jupiter.api.Assertions.assertTrue;
2532

@@ -31,15 +38,48 @@ public class RebalanceST extends AbstractST {
3138
void testKafkaRebalance() {
3239
final TestCaseConfig tcc = getTestCaseConfig();
3340
final int imbalancedPartitions = 20;
41+
final int scaledBrokersCount = 5;
42+
final String rebalanceName = "testrebalance";
43+
final String rebalanceTopicName = "rebalance-topic";
44+
45+
LOGGER.info("Create imbalance by creating topics and scaling brokers afterwards");
46+
KafkaTopicUtils.setupTopicsAndReturn(tcc.namespace(), tcc.kafkaName(), rebalanceTopicName, 5, true, imbalancedPartitions, 1, 1);
47+
KafkaUtils.scaleBrokerReplicasWithWait(tcc.namespace(), tcc.kafkaName(), scaledBrokersCount);
48+
49+
LOGGER.info("Create basic rebalance CR");
50+
KubeResourceManager.get().createOrUpdateResourceWithWait(KafkaSetup.getKafkaRebalance(tcc.namespace(), tcc.kafkaName(), rebalanceName).build());
51+
WaitUtils.waitForKafkaRebalanceProposalStatus(tcc.namespace(), rebalanceName, KafkaRebalanceState.PendingProposal);
3452

35-
KafkaTopicUtils.setupTopicsAndReturn(tcc.namespace(), tcc.kafkaName(), Constants.REPLICATED_TOPICS_PREFIX, 3, true, 1, 1, 1);
36-
KafkaTopicUtils.setupTopicsAndReturn(tcc.namespace(), tcc.kafkaName(), "rebalance-topic", 1, true, imbalancedPartitions, 1, 1);
37-
KubeResourceManager.get().createOrUpdateResourceWithWait(KafkaSetup.getKafkaRebalance(tcc.namespace(), tcc.kafkaName()).build());
38-
LOGGER.info("Verify rebalance proposals");
53+
LOGGER.info("Verify rebalance proposals table");
3954
tcc.page().navigate(PwPageUrls.getKafkaRebalancePage(tcc, tcc.kafkaName()));
4055
PwUtils.waitForLocatorCount(tcc, 1, NodesPageSelectors.NPS_REBALANCE_TABLE_ITEMS, true);
41-
assertTrue(tcc.page().locator(new CssBuilder(NodesPageSelectors.NPS_REBALANCE_PROPOSAL_NAME).nth()));
56+
PwUtils.waitForContainsText(tcc, NodesPageSelectors.NPS_REBALANCE_PROPOSAL_STATUS, KafkaRebalanceState.PendingProposal.name(), true);
57+
assertTrue(tcc.page().locator(NodesPageSelectors.NPS_REBALANCE_PROPOSAL_NAME).allInnerTexts().toString().contains(rebalanceName));
58+
59+
LOGGER.info("Inspect rebalance proposal");
60+
PwUtils.waitForLocatorAndClick(tcc, NodesPageSelectors.NPS_REBALANCE_PROPOSAL_DROPDOWN_BUTTON);
61+
PwUtils.waitForContainsText(tcc, NodesPageSelectors.NPS_REBALANCE_PROPOSAL_DROPDOWN_AUTO_APPROVAL_ENABLED, "false", true);
62+
assertTrue(tcc.page().locator(NodesPageSelectors.NPS_REBALANCE_PROPOSAL_DROPDOWN_MODE).allInnerTexts().toString().toLowerCase(Locale.ENGLISH).contains(KafkaRebalanceMode.FULL.toValue()));
63+
64+
LOGGER.info("Wait for proposal to be in Ready state and check values");
65+
WaitUtils.waitForKafkaRebalanceProposalStatus(tcc.namespace(), rebalanceName, KafkaRebalanceState.ProposalReady);
66+
PwUtils.waitForLocatorAndClick(tcc, NodesPageSelectors.NPS_REBALANCE_PROPOSAL_NAME);
67+
// table values
68+
Map<String, Object> status = ResourceUtils.getKubeResource(KafkaRebalance.class, tcc.namespace(), rebalanceName).getStatus().getOptimizationResult();
69+
PwUtils.waitForContainsText(tcc, NodesPageSelectors.NPS_PROPOSAL_MODAL_DATA_TO_MOVE, status.get("dataToMoveMB").toString(), false);
70+
PwUtils.waitForContainsText(tcc, NodesPageSelectors.NPS_PROPOSAL_MODAL_DATA_MONITORED_PARTITIONS_PERCENTAGE, status.get("monitoredPartitionsPercentage").toString(), false);
71+
PwUtils.waitForContainsText(tcc, NodesPageSelectors.NPS_PROPOSAL_MODAL_DATA_NUMBER_REPLICA_MOVEMENTS, status.get("numReplicaMovements").toString(), false);
72+
PwUtils.waitForContainsText(tcc, NodesPageSelectors.NPS_PROPOSAL_MODAL_DATA_BALANCEDNESS_BEFORE, status.get("onDemandBalancednessScoreBefore").toString(), false);
73+
PwUtils.waitForContainsText(tcc, NodesPageSelectors.NPS_PROPOSAL_MODAL_DATA_BALANCEDNESS_AFTER, status.get("onDemandBalancednessScoreAfter").toString(), false);
74+
PwUtils.waitForLocatorAndClick(tcc, NodesPageSelectors.NPS_PROPOSAL_MODAL_CLOSE_BUTTON);
75+
76+
LOGGER.info("Approve rebalance using UI");
77+
PwUtils.waitForLocatorAndClick(tcc, NodesPageSelectors.NPS_PROPOSAL_ACTION_DROPDOWN_BUTTON);
78+
PwUtils.waitForLocatorAndClick(tcc, NodesPageSelectors.NPS_PROPOSAL_ACTION_APPROVE_BUTTON);
79+
PwUtils.waitForLocatorAndClick(tcc, NodesPageSelectors.NPS_PROPOSAL_MODAL_CONFIRM_BUTTON);
4280

81+
WaitUtils.waitForKafkaRebalanceProposalStatus(tcc.namespace(), rebalanceName, KafkaRebalanceState.Rebalancing);
82+
PwUtils.waitForContainsText(tcc, NodesPageSelectors.NPS_REBALANCE_PROPOSAL_STATUS, KafkaRebalanceState.Rebalancing.name(), true);
4383
}
4484

4585
@AfterEach

0 commit comments

Comments
 (0)