You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by ka...@apache.org on 2022/09/13 03:03:04 UTC
[rocketmq-streams] branch main updated: delete duplicate unit test
This is an automated email from the ASF dual-hosted git repository.
karp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/rocketmq-streams.git
The following commit(s) were added to refs/heads/main by this push:
new a2a2c28b delete duplicate unit test
new 2993c1a5 Merge pull request #215 from selectbook/main
a2a2c28b is described below
commit a2a2c28b6c03ce0281b691f88ff1c6669d790901
Author: selectbook <18...@163.com>
AuthorDate: Tue Sep 13 05:41:45 2022 +0800
delete duplicate unit test
---
.../configurable/ConfigurableComponentTest.java | 107 --------------------
.../streams/configurable/model/Person.java | 109 ---------------------
2 files changed, 216 deletions(-)
diff --git a/rocketmq-streams-configurable/src/test/java/org/apache/rocketmq/streams/configurable/ConfigurableComponentTest.java b/rocketmq-streams-configurable/src/test/java/org/apache/rocketmq/streams/configurable/ConfigurableComponentTest.java
deleted file mode 100644
index 0dba8d57..00000000
--- a/rocketmq-streams-configurable/src/test/java/org/apache/rocketmq/streams/configurable/ConfigurableComponentTest.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.rocketmq.streams.configurable;
-
-import java.util.List;
-import org.apache.rocketmq.streams.common.component.AbstractComponent;
-import org.apache.rocketmq.streams.common.component.ComponentCreator;
-import org.apache.rocketmq.streams.common.configurable.IConfigurableService;
-import org.apache.rocketmq.streams.configurable.model.Person;
-import org.junit.Test;
-
-import static junit.framework.TestCase.assertTrue;
-
-public class ConfigurableComponentTest {
-
- @Test
- public void testInsertConfigurable() {
- String namespace = "org.apache.configurable.test";
- ConfigurableComponent configurableComponent = ConfigurableComponent.getInstance(namespace);
- Person person = createPerson(namespace);
- configurableComponent.insert(person);//完成数据存储,在配置文件配置存储类型,支持内存,db和文件,默认是内存
- //查询只操作内存,存储的数据定时加载到内存,刚插入的数据,还未加载,查询不到
- assertTrue(configurableComponent.queryConfigurable("person", "personName") == null);
- configurableComponent.refreshConfigurable(namespace);//强制加载数据到内存,可以查询数据
- assertTrue(configurableComponent.queryConfigurable("person", "peronName") != null);
- }
-
- @Test
- public void testConfigurableENVDependence() {
- String namespace = "org.apache.configurable.test";
- ConfigurableComponent configurableComponent = ConfigurableComponent.getInstance(namespace);
- Person person = createPerson(namespace);
- person.setName("persion.name");//对于有ENVDependence的字段,可以不存储真值,存储一个key,把真值配置在配置文件中
- configurableComponent.insert(person);//完成数据存储,在配置文件配置存储类型,支持内存,db和文件,默认是内存
- ComponentCreator.getProperties().put("persion.name", "realName");//这个代表真实的配置文件,启动时会把配置文件的内容加载到ComponentCreator.getProperties()中
- configurableComponent.refreshConfigurable(namespace);//刷新存储
- person = configurableComponent.queryConfigurable("person", "peronName");
- assertTrue(person.getName().equals("realName"));
- }
-
- @Test
- public void testSupportParentNameSpace() {
- String namespace = "org.apache.configurable.test";
- ConfigurableComponent configurableComponent = ConfigurableComponent.getInstance(namespace);
- Person person = createPerson(namespace);
- Person otherPerson = createPerson("org.apache.configuable.test1");
- configurableComponent.insert(person);
- configurableComponent.insert(otherPerson);
- configurableComponent.refreshConfigurable(namespace);
- //只加载自己命名空间的对象
- List<Person> personList = configurableComponent.queryConfigurableByType("person");
- assertTrue(personList.size() == 1);
-
- /**
- * 顶级命名空间的对象,所有namespace都可见
- */
- Person thirdPerson = createPerson(IConfigurableService.PARENT_CHANNEL_NAME_SPACE);
- configurableComponent.insert(thirdPerson);
- configurableComponent.refreshConfigurable(namespace);//只加载自己命名空间的对象
- personList = configurableComponent.queryConfigurableByType("person");
- assertTrue(personList.size() == 2);
- }
-
- //测试定时加载逻辑,当对象的updateFlag值变化后,才会被替换旧对象
- @Test
- public void testAutoLoader() throws InterruptedException {
- ComponentCreator.getProperties().put(AbstractComponent.POLLING_TIME, "1");//1秒后动态加载对象
- String namespace = "org.apache.configurable.test";
- ConfigurableComponent configurableComponent = ConfigurableComponent.getInstance(namespace);
- Person person = createPerson(namespace);
- configurableComponent.insert(person);
- Thread.sleep(2000);//1秒后,新插入的对象会被加载
- person = configurableComponent.queryConfigurable("person", "peronName");
- assertTrue(person != null);
-
- }
-
- /**
- * 创建configurable对象
- *
- * @param namespace
- * @return
- */
- protected Person createPerson(String namespace) {
- Person person = new Person();
- person.setName("chris");
- person.setAge(18);
- person.setNameSpace(namespace);
- person.setConfigureName("peronName");
- person.setType("person");
- return person;
- }
-}
diff --git a/rocketmq-streams-configurable/src/test/java/org/apache/rocketmq/streams/configurable/model/Person.java b/rocketmq-streams-configurable/src/test/java/org/apache/rocketmq/streams/configurable/model/Person.java
deleted file mode 100644
index 0c7de985..00000000
--- a/rocketmq-streams-configurable/src/test/java/org/apache/rocketmq/streams/configurable/model/Person.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.rocketmq.streams.configurable.model;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.apache.rocketmq.streams.common.configurable.BasedConfigurable;
-import org.apache.rocketmq.streams.common.configurable.annotation.ENVDependence;
-
-public class Person extends BasedConfigurable {
- @ENVDependence
- private String name;
- private int age;
- private Boolean isMale;
- private List<String> addresses;
- private Map<String, Integer> childName2Age;
-
- public static Person createPerson(String namespace) {
- Person person = new Person();
- person.setNameSpace(namespace);
- person.setType("person");
- person.setConfigureName("Chris");
- person.setName("Chris");
- List<String> addresses = new ArrayList<>();
- addresses.add("huilongguan");
- addresses.add("shangdi");
- person.setAddresses(addresses);
- Map<String, Integer> childName2Age = new HashMap<>();
- childName2Age.put("yuanyahan", 8);
- childName2Age.put("yuanruxi", 4);
- person.setChildName2Age(childName2Age);
- person.setMale(true);
- person.setAge(18);
- return person;
- }
-
- @Override
- public String toString() {
- return "Person{" + "name='" + name + '\'' + ", age=" + age + ", isMale=" + isMale + ", addresses=" + addresses
- + ", childName2Age=" + childName2Age + '}';
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public int getAge() {
- return age;
- }
-
- public void setAge(int age) {
- this.age = age;
- }
-
- public Boolean getMale() {
- return isMale;
- }
-
- public void setMale(Boolean male) {
- isMale = male;
- }
-
- public List<String> getAddresses() {
- return addresses;
- }
-
- public void setAddresses(List<String> addresses) {
- this.addresses = addresses;
- }
-
- public Map<String, Integer> getChildName2Age() {
- return childName2Age;
- }
-
- public void setChildName2Age(Map<String, Integer> childName2Age) {
- this.childName2Age = childName2Age;
- }
-
- @Override
- public Object clone() {
- Person person = null;
- try {
- person = (Person)super.clone();
- } catch (CloneNotSupportedException e) {
- System.out.println("clone error " + e);
- }
- return person;
- }
-}