Package com.dianping.cat.configuration.client.entity

Examples of com.dianping.cat.configuration.client.entity.ClientConfig


import com.dianping.cat.configuration.client.transform.DefaultXmlBuilder;

public class ConfigTest {
  @Test
  public void testClient() throws Exception {
    ClientConfig clientConfig = loadConfig("client-config.xml");
    ClientConfig globalConfig = loadConfig("global-config.xml");

    Assert.assertEquals("client", clientConfig.getMode());

    globalConfig.accept(new ClientConfigMerger(clientConfig));
    clientConfig.accept(new ClientConfigValidator());

    List<Server> servers = clientConfig.getServers();

    Assert.assertEquals(3, servers.size());
View Full Code Here


  }

  private ClientConfig loadConfig(String configXml) throws IOException, SAXException {
    InputStream in = getClass().getResourceAsStream(configXml);
    String xml = Files.forIO().readFrom(in, "utf-8");
    ClientConfig clientConfig = DefaultSaxParser.parse(xml);

    return clientConfig;
  }
View Full Code Here

  }

  @Test
  public void testConfig() throws Exception {
    String source = Files.forIO().readFrom(getClass().getResourceAsStream("config.xml"), "utf-8");
    ClientConfig root = DefaultSaxParser.parse(source);
    String xml = new DefaultXmlBuilder().buildXml(root);
    String expected = source;

    Assert.assertEquals("XML is not well parsed!", expected.replace("\r", ""), xml.replace("\r", ""));
  }
View Full Code Here

public class CatClientTest extends CatTestCase {
  private Queue<MessageTree> m_queue;

  @BeforeClass
  public static void beforeClass() throws IOException {
    ClientConfig clientConfig = new ClientConfig();

    clientConfig.setMode("client");
    clientConfig.addDomain(new Domain("Test").setEnabled(true));

    File configFile = new File("/data/appdatas/cat/client.xml").getCanonicalFile();

    configFile.getParentFile().mkdirs();

    Files.forIO().writeTo(configFile, clientConfig.toString());

    // Cat.destroy();
    Cat.initialize(configFile);
  }
View Full Code Here

public class MessageProducerTest extends CatTestCase {
  private Queue<MessageTree> m_queue;

  @BeforeClass
  public static void beforeClass() throws IOException {
    ClientConfig clientConfig = new ClientConfig();

    clientConfig.setMode("client");
    clientConfig.addDomain(new Domain("Test").setEnabled(true));

    File configFile = new File("target/client.xml").getCanonicalFile();

    configFile.getParentFile().mkdirs();

    Files.forIO().writeTo(configFile, clientConfig.toString());

    Cat.destroy();
    Cat.initialize(configFile);
  }
View Full Code Here

    Assert.assertEquals(expected, sb.toString());
  }

  protected File getConfigurationFile() {
    try {
      ClientConfig config = new ClientConfig();

      config.setMode("client");
      config.addDomain(new Domain("cat").setMaxMessageSize(8));
      config.addServer(new Server("localhost"));

      File file = new File("target/cat-config.xml");

      Files.forIO().writeTo(file, config.toString());
      return file;
    } catch (IOException e) {
      throw new RuntimeException("Unable to create cat-config.xml file!");
    }
  }
View Full Code Here

public abstract class CatTestCase extends ComponentTestCase {
  protected File getConfigurationFile() {
    if (isCatServerAlive()) {
      try {
        ClientConfig config = new ClientConfig();

        config.setMode("client");
        config.addDomain(new Domain("cat"));
        config.addServer(new Server("localhost").setPort(2280));

        File file = new File("target/cat-config.xml");

        Files.forIO().writeTo(file, config.toString());
        return file;
      } catch (IOException e) {
        return null;
      }
    }
View Full Code Here

  public static void initialize(String... servers) {
    File configFile = null;

    try {
      configFile = File.createTempFile("cat-client", ".xml");
      ClientConfig config = new ClientConfig().setMode("client");

      for (String server : servers) {
        config.addServer(new Server(server));
      }

      Files.forIO().writeTo(configFile, config.toString());
    } catch (IOException e) {
      e.printStackTrace();
    }
    initialize(configFile);
  }
View Full Code Here

  public int getTaggedTransactionCacheSize() {
    return 1024;
  }

  public void initialize(File configFile) throws Exception {
    ClientConfig globalConfig = null;
    ClientConfig clientConfig = null;

    // read the global configure from local file system
    // so that OPS can:
    // - configure the cat servers to connect
    // - enable/disable Cat for specific domain(s)
    if (configFile != null) {
      if (configFile.exists()) {
        String xml = Files.forIO().readFrom(configFile.getCanonicalFile(), "utf-8");

        globalConfig = DefaultSaxParser.parse(xml);
        m_logger.info(String.format("Global config file(%s) found.", configFile));
      } else {
        m_logger.warn(String.format("Global config file(%s) not found, IGNORED.", configFile));
      }
    }

    // load the client configure from Java class-path
    clientConfig = loadConfigFromEnviroment();

    if (clientConfig == null) {
      clientConfig = loadConfigFromXml();
    }

    // merge the two configures together to make it effected
    if (globalConfig != null && clientConfig != null) {
      globalConfig.accept(new ClientConfigMerger(clientConfig));
    }

    if (clientConfig != null) {
      clientConfig.accept(new ClientConfigValidator());
    }

    m_config = clientConfig;
  }
View Full Code Here

        prop.load(in);

        String appName = prop.getProperty("app.name");

        if (appName != null) {
          ClientConfig config = new ClientConfig();

          config.addDomain(new Domain(appName));
          m_logger.info(String.format("Find domain name %s from app.properties.", appName));
          return config;
        } else {
          m_logger.info(String.format("Can't find app.name from app.properties."));
          return null;
View Full Code Here

TOP

Related Classes of com.dianping.cat.configuration.client.entity.ClientConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.