-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1624 from chengyouling/develop-ut
add rocketmq grayscale UT test
- Loading branch information
Showing
24 changed files
with
1,212 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...cale/mq-config-common/src/test/java/io/sermant/mq/grayscale/config/CommonConfigUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.sermant.mq.grayscale.config; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* common config utils | ||
* | ||
* @author chengyouling | ||
* @since 2024-09-18 | ||
**/ | ||
public class CommonConfigUtils { | ||
public static GrayTagItem getGrayTagItem() { | ||
GrayTagItem item = new GrayTagItem(); | ||
item.setConsumerGroupTag("gray"); | ||
Map<String, String> serviceMeta = new HashMap<>(); | ||
serviceMeta.put("x_lane_tag", "gray" ); | ||
item.setServiceMeta(serviceMeta); | ||
Map<String, String> trafficTag = new HashMap<>(); | ||
trafficTag.put("x_lane_canary", "gray"); | ||
item.setTrafficTag(trafficTag); | ||
return item; | ||
} | ||
|
||
public static MqGrayscaleConfig getMqGrayscaleConfig() { | ||
MqGrayscaleConfig config = new MqGrayscaleConfig(); | ||
config.setGrayscale(getGrayscale(getGrayTagItem())); | ||
config.setEnabled(true); | ||
return config; | ||
} | ||
|
||
|
||
public static List<GrayTagItem> getGrayscale(GrayTagItem item) { | ||
List<GrayTagItem> grayscale = new ArrayList<>(); | ||
grayscale.add(item); | ||
return grayscale; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...yscale/mq-config-common/src/test/java/io/sermant/mq/grayscale/config/GrayTagItemTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.sermant.mq.grayscale.config; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* GrayTagItem test | ||
* | ||
* @author chengyouling | ||
* @since 2024-09-18 | ||
**/ | ||
public class GrayTagItemTest { | ||
@Test | ||
public void testMatchPropertiesByServiceMeta() { | ||
Map<String, String> properties = new HashMap<>(); | ||
properties.put("x_lane_tag", "gray"); | ||
GrayTagItem item = CommonConfigUtils.getGrayTagItem(); | ||
Assert.assertTrue(item.matchPropertiesByServiceMeta(properties)); | ||
|
||
properties.put("x_lane_tag", "red"); | ||
Assert.assertFalse(item.matchPropertiesByServiceMeta(properties)); | ||
} | ||
|
||
@Test | ||
public void testUpdateTrafficTags() { | ||
GrayTagItem itemResource = CommonConfigUtils.getGrayTagItem(); | ||
List<GrayTagItem> grayscale = new ArrayList<>(); | ||
GrayTagItem item = CommonConfigUtils.getGrayTagItem(); | ||
item.getTrafficTag().put("x_lane_red", "red"); | ||
grayscale.add(item); | ||
itemResource.updateTrafficTags(grayscale); | ||
Assert.assertSame(2, itemResource.getTrafficTag().size()); | ||
|
||
itemResource = CommonConfigUtils.getGrayTagItem(); | ||
itemResource.setConsumerGroupTag("red"); | ||
itemResource.updateTrafficTags(grayscale); | ||
Assert.assertSame(1, itemResource.getTrafficTag().size()); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
.../mq-config-common/src/test/java/io/sermant/mq/grayscale/config/MqGrayConfigCacheTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.sermant.mq.grayscale.config; | ||
|
||
import io.sermant.core.service.dynamicconfig.common.DynamicConfigEventType; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* MqGrayConfigCache test | ||
* | ||
* @author chengyouling | ||
* @since 2024-09-18 | ||
**/ | ||
public class MqGrayConfigCacheTest { | ||
@Test | ||
public void testSetCacheConfig() { | ||
MqGrayscaleConfig config = getMqGrayscaleConfig(CommonConfigUtils.getGrayTagItem()); | ||
MqGrayConfigCache.setCacheConfig(config, DynamicConfigEventType.CREATE); | ||
Assert.assertTrue(MqGrayConfigCache.getCacheConfig().isEnabled()); | ||
|
||
// consumeMode changed will not update config | ||
config.getBase().setConsumeMode(ConsumeModeEnum.BASE); | ||
MqGrayConfigCache.setCacheConfig(config, DynamicConfigEventType.MODIFY); | ||
Assert.assertSame(ConsumeModeEnum.BASE, MqGrayConfigCache.getCacheConfig().getBase().getConsumeMode()); | ||
|
||
// serviceMeta changed will not update config | ||
GrayTagItem item = CommonConfigUtils.getGrayTagItem(); | ||
item.getServiceMeta().put("x_lane_tag", "red" ); | ||
MqGrayscaleConfig config1 = getMqGrayscaleConfig(item); | ||
MqGrayConfigCache.setCacheConfig(config1, DynamicConfigEventType.MODIFY); | ||
Assert.assertEquals("gray", | ||
MqGrayConfigCache.getCacheConfig().getGrayscale().get(0).getServiceMeta().get("x_lane_tag")); | ||
|
||
// trafficTag changed will not update config | ||
GrayTagItem item1 = CommonConfigUtils.getGrayTagItem(); | ||
item1.getTrafficTag().put("x_lane_canary", "red"); | ||
item1.getServiceMeta().put("x_lane_tag", "red" ); | ||
MqGrayscaleConfig config2 = getMqGrayscaleConfig(item1); | ||
MqGrayConfigCache.setCacheConfig(config2, DynamicConfigEventType.MODIFY); | ||
Assert.assertEquals("red", | ||
MqGrayConfigCache.getCacheConfig().getGrayscale().get(0).getTrafficTag().get("x_lane_canary")); | ||
} | ||
|
||
private MqGrayscaleConfig getMqGrayscaleConfig(GrayTagItem item) { | ||
MqGrayscaleConfig config = new MqGrayscaleConfig(); | ||
config.setEnabled(true); | ||
config.setGrayscale(CommonConfigUtils.getGrayscale(item)); | ||
return config; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
.../mq-config-common/src/test/java/io/sermant/mq/grayscale/config/MqGrayscaleConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.sermant.mq.grayscale.config; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* MqGrayscaleConfig test | ||
* | ||
* @author chengyouling | ||
* @since 2024-09-18 | ||
**/ | ||
public class MqGrayscaleConfigTest { | ||
@Test | ||
public void testGetGrayTagsByServiceMeta() { | ||
MqGrayscaleConfig config = CommonConfigUtils.getMqGrayscaleConfig(); | ||
Map<String, String> properties = new HashMap<>(); | ||
properties.put("x_lane_tag", "gray" ); | ||
Assert.assertSame(1, config.getGrayTagsByServiceMeta(properties).size()); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...common/src/test/java/io/sermant/mq/grayscale/config/rocketmq/RocketMqConfigUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.sermant.mq.grayscale.config.rocketmq; | ||
|
||
import io.sermant.mq.grayscale.config.CommonConfigUtils; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* RocketMqConfigUtils test | ||
* | ||
* @author chengyouling | ||
* @since 2024-09-18 | ||
**/ | ||
public class RocketMqConfigUtilsTest { | ||
@Test | ||
public void testBaseGroupTagChangeMap() { | ||
RocketMqConfigUtils.setBaseGroupTagChangeMap("127.0.0.1@TEST@base", true); | ||
Assert.assertTrue(RocketMqConfigUtils.getBaseGroupTagChangeMap("127.0.0.1@TEST@base")); | ||
Assert.assertFalse(RocketMqConfigUtils.getBaseGroupTagChangeMap("127.0.0.1@TEST@base1")); | ||
} | ||
|
||
@Test | ||
public void testGrayGroupTagChangeMap() { | ||
RocketMqConfigUtils.setGrayGroupTagChangeMap("127.0.0.1@TEST@base-gray", true); | ||
Assert.assertTrue(RocketMqConfigUtils.getGrayGroupTagChangeMap("127.0.0.1@TEST@base-gray")); | ||
Assert.assertFalse(RocketMqConfigUtils.getGrayGroupTagChangeMap("127.0.0.1@TEST@base-gray1")); | ||
} | ||
|
||
@Test | ||
public void testUpdateChangeFlag() { | ||
RocketMqConfigUtils.setBaseGroupTagChangeMap("127.0.0.1@TEST@base", false); | ||
RocketMqConfigUtils.setGrayGroupTagChangeMap("127.0.0.1@TEST@base-gray", false); | ||
RocketMqConfigUtils.updateChangeFlag(); | ||
Assert.assertTrue(RocketMqConfigUtils.getBaseGroupTagChangeMap("127.0.0.1@TEST@base")); | ||
Assert.assertTrue(RocketMqConfigUtils.getGrayGroupTagChangeMap("127.0.0.1@TEST@base-gray")); | ||
} | ||
|
||
@Test | ||
public void testRecordTrafficTagsSet() { | ||
RocketMqConfigUtils.recordTrafficTagsSet(CommonConfigUtils.getMqGrayscaleConfig()); | ||
Assert.assertSame(1, RocketMqConfigUtils.getGrayTagsSet().size()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.