Yesterday, I completed the XML file parsing class based on DOM. Today, I quickly put it into practice. I have to say that there are many pits in practice.

Originally, this project is to standardize the configuration items of each service when using MySQL database. Since I have been in contact with Java services before, I have a relatively good understanding of these services, and the configuration items of everyone are basically consistent. Today, the analysis of the configuration items of all services is a great eye-opener.

  • I don’t know. It’s a wonderful world.

The first is the hierarchy of configuration items. Generally speaking, there is a root node as the root node, then the child nodes are each service node, below the service node are the service version node, then the change and unchange nodes, and then the concrete content. How people calculate as day calculate, calculate to calculate as dog belt.

Look at the picture first:

For one thing, all nodes are Zknode. There are different configuration modules under each version, and then the child nodes configure the details.

Actually there is no value configuration item, I really want to take the dog.

Then there is the MySQL configuration, which is a refreshing world view.

Here’s what I took from the XML general configuration file:


                <zknode name="datadb.username" value="* * * *"/>
                <zknode name="db.host.r" value="* * * *"/>
                <zknode name="dbdata.host.w" value="*"/>
                <zknode name="datadb.port" value="*"/>
                <zknode name="datadb.databasev3" value="* * * * *"/>
                <zknode name="datadb.host.w" value="* * * * *"/>
Copy the code

               <zknode name="v3.db" value="* * * * * *"/>
                <zknode name="v3.user" value="* * * * * *"/>
                <zknode name="work.db" value="* * * * * *"/>
                <zknode name="work.host" value="* * * * * *"/>
                <zknode name="v3.passwd" value="* * * * * *"/>
Copy the code
                <zknode name="DB_CONNECTION" value="* * * * * *"/>
                <zknode name="DB_HOST" value="* * * * * *"/>
                <zknode name="DB_DATABASE" value="* * * * * *"/>
                <zknode name="DB_PASSWORD" value="* * * * * *"/>
Copy the code
                <zknode name="mysql.DB_DATABASE" value="* * *"/>
                <zknode name="redis.REDIS_PORT" value="* * *"/>
Copy the code
                <zknode name="ds.druid.username" value="* * * *"/>
                <zknode name="ds.druid.url"  value="* * * *"/>
Copy the code

The 100 database configurations are omitted

Remember, the teasing is done, the work must be done. After repeated attempts, a solution script was finally completed.

I think I need a widescreen monitor.


package com.fun.ztest.groovy

import com.fun.frame.httpclient.FanLibrary
import com.fun.utils.XMLUtil
import org.slf4j.Logger
import org.slf4j.LoggerFactory

class Td extends FanLibrary {

    private static Logger logger = LoggerFactory.getLogger(Td.class)

    public static void main(String[] args) {


        def xml = XMLUtil.parseXml("/Users/fv/Downloads/d.xml"."root")
        xml.get(0).getChildren().each {
            logger.error("Service name :{}", it.getAttrs().get(0).getValue())
            def children = it.getChildren()
            children.each {
                def attr1 = it.getAttrs()
                def name = attr1.get(0).getValue()
                if (name ==~ /[vV]\d.\d+/) {
                    logger.error("The zk version: ${name}")
                    def children1 = it.getChildren()
                    children1.each {
                        def children2 = it.getChildren()
                        children2.each {
                            def attrs = it.getAttrs()
                            if (attrs.size() > 1) {
                                def var = attrs.get(0).getValue()
                                def value = attrs.get(1).getValue()
                                if(! (value ==~/\d+/)) {
                                    if (var.contains("druid") || var.contains("db") || var.contains("user") || value.contains("mysql") || value.contains("neworiental") || value.contains("neworiental")) {
                                        if(! value.contains("{") && !value.contains(".txt") && !var.contains("service") && !var.contains("maill") && !var.contains("host") && !var.contains("driver") && !var.contains("filters") && !var.contains("center") && !var.contains("rabbit") && !var.contains("order") && !value.contains("http"))
                                            logger.info("key: {},value: {}", var, value)
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        testOver()
    }


}

Copy the code

The public number FunTester was first launched, original sharing enthusiasts, Tencent Cloud and Denver community home page recommendation, Zhihu seven level original author, welcome to pay attention to, exchange, prohibit unauthorized reprinting by third parties.

FunTester hot text selection

  • Programming thinking for everyone
  • 2020 Tester self-improvement
  • Fiddler Everywhere is the future
  • Test development engineer work skills
  • Selenium4 IDE, it’s finally here
  • Automated test soul three questions: What, why, and what to do
  • Why is test coverage so important
  • Spit out a slot, non-measurement by mistake.
  • Automated testing framework
  • End-to-end testing in Agile