Ejemplo n.º 1
0
  @Test
  public void sendDependencyTransaction() throws Exception {
    int size = 10;
    for (int i = 0; i < size; i++) {
      Transaction t = Cat.getProducer().newTransaction("SQL", "User.select" + i % 10);
      Cat.getProducer().newEvent("SQL.Method", "Select").setStatus(Message.SUCCESS);
      Cat.getProducer()
          .newEvent("SQL.Database", "jdbc:mysql://192.168.7.43:3306/database" + i % 4)
          .setStatus(Message.SUCCESS);
      t.addData("select * from hostinfo");
      t.setStatus(Message.SUCCESS);
      t.complete();
    }

    for (int i = 0; i < size; i++) {
      Transaction t = Cat.getProducer().newTransaction("PigeonCall", "Method3");
      Cat.getProducer().newEvent("PigeonCall.server", "192.168.64.11:2280");
      t.addData("key and value");

      Thread.sleep(1);
      t.complete();
    }

    for (int i = 0; i < size; i++) {
      Transaction t = Cat.getProducer().newTransaction("PigeonService", "Method6");
      Cat.getProducer().newEvent("PigeonService.client", "192.168.7.77");
      t.addData("key and value");

      Thread.sleep(51);
      t.complete();
    }
  }
Ejemplo n.º 2
0
  @Test
  public void sendPigeonServerTransaction() throws Exception {
    for (int i = 0; i < 100; i++) {
      Transaction t = Cat.getProducer().newTransaction("PigeonService", "Method6");
      Cat.getProducer().newEvent("PigeonService.client", "192.168.7.77");
      t.addData("key and value");

      Thread.sleep(51);
      t.complete();
    }
    for (int i = 0; i < 200; i++) {
      Transaction t = Cat.getProducer().newTransaction("PigeonService", "Method8");
      Cat.getProducer().newEvent("PigeonService.client", "192.168.7.20");
      t.addData("key and value");

      Thread.sleep(1);
      t.complete();
    }

    for (int i = 0; i < 300; i++) {
      Transaction t = Cat.getProducer().newTransaction("PigeonService", "Method5");
      Cat.getProducer().newEvent("PigeonService.client", "192.168.7.231");
      t.addData("key and value");

      Thread.sleep(1);
      t.complete();
    }
    Thread.sleep(100);
  }
Ejemplo n.º 3
0
  @Test
  public void sendSqlTransaction() throws Exception {
    for (int k = 0; k < 5; k++) {
      for (int i = 0; i < 100; i++) {
        Transaction t = Cat.getProducer().newTransaction("SQL", "User.select" + i % 10);
        Cat.getProducer().newEvent("SQL.Method", "Select").setStatus(Message.SUCCESS);
        Cat.getProducer()
            .newEvent("SQL.Database", "jdbc:mysql://192.168.7.43:3306/database" + k)
            .setStatus(Message.SUCCESS);
        t.addData("select * from hostinfo");
        t.setStatus(Message.SUCCESS);
        t.complete();

        Transaction t2 = Cat.getProducer().newTransaction("SQL", "User.insert" + i % 10);
        Cat.getProducer().newEvent("SQL.Method", "Update").setStatus(Message.SUCCESS);
        Cat.getProducer()
            .newEvent("SQL.Database", "jdbc:mysql://192.168.7.43:3306/database" + k)
            .setStatus(Message.SUCCESS);
        t2.addData("update * from hostinfo");
        t2.complete();

        Transaction t3 = Cat.getProducer().newTransaction("SQL", "User.delete" + i % 10);
        Cat.getProducer().newEvent("SQL.Method", "Delete").setStatus(Message.SUCCESS);
        Cat.getProducer()
            .newEvent("SQL.Database", "jdbc:mysql://192.168.7.43:3306/database" + k)
            .setStatus(Message.SUCCESS);
        t3.addData("delete * from hostinfo");
        t3.setStatus(Message.SUCCESS);
        t3.complete();
      }
    }
    Thread.sleep(1000);
  }
Ejemplo n.º 4
0
  @Test
  public void sendCacheTransactionWithMissed() throws Exception {
    for (int i = 0; i < 130; i++) {
      Transaction t = Cat.getProducer().newTransaction("Cache.kvdb", "Method" + i % 10);
      Cat.getProducer().newEvent("Cache.kvdb", "Method" + i % 10 + ":missed");
      t.addData("key and value");

      Transaction t2 = Cat.getProducer().newTransaction("Cache.web", "Method" + i % 10);
      Cat.getProducer().newEvent("Cache.web", "Method" + i % 10 + ":missed");
      t2.addData("key and value");
      Thread.sleep(2);
      t2.complete();
      t.complete();

      Transaction t3 = Cat.getProducer().newTransaction("Cache.memcached", "Method" + i % 10);
      t3.addData("key and value");
      Thread.sleep(3);
      t3.complete();
    }

    Transaction t2 = Cat.getProducer().newTransaction("Cache.web", "Method");
    t2.addData("key and value");
    Thread.sleep(2);
    t2.complete();
    Thread.sleep(1000);
  }
Ejemplo n.º 5
0
  @Test
  public void sendLongCacheTransaction() throws Exception {
    for (int i = 0; i < 100; i++) {
      Transaction t = Cat.getProducer().newTransaction("Cache.kvdb", "Method6");
      Cat.getProducer().newEvent("PigeonService.client", "192.168.7.77");
      t.addData("key and value");

      Thread.sleep(11);
      Transaction t2 = Cat.getProducer().newTransaction("Cache.local", "Method");
      Cat.getProducer().newEvent("PigeonService.client", "192.168.7.77");
      t2.addData("key and value");

      Thread.sleep(11);
      t2.complete();
      t.complete();
    }
  }
Ejemplo n.º 6
0
 @Test
 public void sendLongSQLTransaction() throws Exception {
   for (int i = 0; i < 10; i++) {
     Transaction t = Cat.getProducer().newTransaction("SQL", "Method6");
     t.addData("key and value");
     Thread.sleep(102);
     t.complete();
   }
 }
Ejemplo n.º 7
0
  @Test
  public void sendMessage() throws Exception {
    for (int i = 0; i < 100; i++) {
      Transaction t = Cat.getProducer().newTransaction("Test", "Test");

      t.addData("key and value");
      t.complete();
    }
    Thread.sleep(1000);
  }
Ejemplo n.º 8
0
  @Test
  public void sendSendSqlErrorMessage() throws Exception {
    for (int i = 0; i < 100; i++) {
      Transaction t = Cat.getProducer().newTransaction("SQL", "Test");

      t.addData("key and value");
      t.setStatus(new NullPointerException());
      t.complete();
    }
    Thread.sleep(1000);
  }
Ejemplo n.º 9
0
  @Test
  public void sendPigeonClientTransaction() throws Exception {
    for (int i = 0; i < 100; i++) {
      Transaction t = Cat.getProducer().newTransaction("PigeonCall", "Method3");
      Cat.getProducer().newEvent("PigeonCall.server", "192.168.64." + i + ":2280");
      t.addData("key and value");

      Thread.sleep(1);
      t.complete();
    }
    for (int i = 0; i < 100; i++) {
      Transaction t = Cat.getProducer().newTransaction("PigeonCall", "Method3");
      Cat.getProducer().newEvent("PigeonCall.server", "192.168.64.11:2280");
      t.addData("key and value");

      Thread.sleep(1);
      t.complete();
    }
    for (int i = 0; i < 200; i++) {
      Transaction t = Cat.getProducer().newTransaction("PigeonCall", "Method3");
      Cat.getProducer().newEvent("PigeonCall.server", "192.168.7.24:8080");
      Cat.getProducer().logEvent("RemoteCall", "Test", Message.SUCCESS, "MessageID");
      t.addData("key and value");

      Thread.sleep(1);
      t.complete();
    }

    for (int i = 0; i < 300; i++) {
      Transaction t = Cat.getProducer().newTransaction("PigeonCall", "Method3");
      Cat.getProducer().newEvent("PigeonCall.server", "192.168.7.39:8080");
      t.addData("key and value");

      Thread.sleep(1);
      t.complete();
    }
    Thread.sleep(100);
  }
Ejemplo n.º 10
0
  @Test
  public void sentHackPigenTransaction() throws Exception {
    for (int i = 0; i < 200; i++) {
      Transaction t = Cat.getProducer().newTransaction("PigeonCall", "Method3");
      Cat.getProducer().newEvent("PigeonCall.server", "192.168.7.24:8080");
      Cat.getProducer().logEvent("RemoteCall", "Pigeon", Message.SUCCESS, "MessageID");
      t.addData("key and value");

      Thread.sleep(1);
      Cat.getManager().getThreadLocalMessageTree().setDomain("Pigeon");
      Cat.getManager().getThreadLocalMessageTree().setMessageId("Cat-c0a81a38-374214-1203");
      t.complete();
    }
  }
Ejemplo n.º 11
0
  @Test
  public void sendMaxMessage() throws Exception {
    long time = System.currentTimeMillis();
    int i = 10;

    while (i > 0) {
      i++;
      Transaction total = Cat.newTransaction("Cat", "Test");
      Transaction t = Cat.getProducer().newTransaction("Cache.kvdb", "Method" + i % 10);
      t.setStatus(Message.SUCCESS);
      Cat.getProducer().newEvent("Cache.kvdb", "Method" + i % 10 + ":missed");
      t.addData("key and value");

      Transaction t2 = Cat.getProducer().newTransaction("Cache.web", "Method" + i % 10);
      Cat.getProducer().newEvent("Cache.web", "Method" + i % 10 + ":missed");
      t2.addData("key and value");
      t2.setStatus(Message.SUCCESS);
      t2.complete();

      Transaction t3 = Cat.getProducer().newTransaction("Cache.memcached", "Method" + i % 10);
      t3.addData("key and value");
      t3.setStatus(Message.SUCCESS);
      t3.complete();

      Transaction t4 = Cat.getProducer().newTransaction("Cache.memcached", "Method" + i % 10);
      t4.addData("key and value");
      t4.setStatus(Message.SUCCESS);
      t4.complete();

      Transaction t5 = Cat.getProducer().newTransaction("Cache.memcached", "Method" + i % 10);
      t5.addData("key and value");
      t5.setStatus(Message.SUCCESS);
      t5.complete();

      Transaction t6 = Cat.getProducer().newTransaction("Cache.memcached", "Method" + i % 10);
      t6.addData("key and value");
      t6.setStatus(Message.SUCCESS);
      t6.complete();

      Transaction t7 = Cat.getProducer().newTransaction("Cache.memcached", "Method" + i % 10);
      t7.addData("key and value");
      t7.setStatus(Message.SUCCESS);
      t7.complete();

      Transaction t8 = Cat.getProducer().newTransaction("Cache.memcached", "Method" + i % 10);
      t8.addData("key and value");
      t8.setStatus(Message.SUCCESS);
      t8.complete();

      Transaction t9 = Cat.getProducer().newTransaction("Cache.memcached", "Method" + i % 10);
      t9.addData("key and value");
      t9.setStatus(Message.SUCCESS);
      t9.complete();
      t.complete();

      total.setStatus(Transaction.SUCCESS);
      t.complete();

      if (i % 10000 == 0) {
        long duration = System.currentTimeMillis() - time;
        System.out.println(
            "[" + duration + "ms]" + "[total]" + i + "[每秒" + i / duration * 1000 + "]");
      }
    }
    Thread.sleep(10 * 1000);
  }
Ejemplo n.º 12
0
  /**
   * 保存swallowMessage到数据库
   *
   * @throws ServerDaoException
   */
  @Override
  public Packet sendMessage(Packet pkt) throws ServerDaoException {
    if (pkt == null) {
      throw new IllegalArgumentException("Argument of remote service could not be null.");
    }
    Packet pktRet = null;
    SwallowMessage swallowMessage;
    String topicName;
    String sha1;
    switch (pkt.getPacketType()) {
      case PRODUCER_GREET:
        LOGGER.info(
            "[Got Greet][From="
                + ((PktProducerGreet) pkt).getProducerIP()
                + "][Version="
                + ((PktProducerGreet) pkt).getProducerVersion()
                + "]");
        // 返回ProducerServer地址
        pktRet = new PktSwallowPACK(producerServerIP);
        break;
      case OBJECT_MSG:
        topicName = ((PktMessage) pkt).getDestination().getName();

        // 验证topicName是否在白名单里
        boolean isValid = topicWhiteList.isValid(topicName);
        if (!isValid) {
          throw new IllegalArgumentException(
              "Invalid topic("
                  + topicName
                  + "), because it's not in whitelist, please contact swallow group for support.");
        }

        swallowMessage = ((PktMessage) pkt).getContent();
        sha1 = SHAUtil.generateSHA(swallowMessage.getContent());
        pktRet = new PktSwallowPACK(sha1);
        // 设置swallowMessage的sha-1
        swallowMessage.setSha1(sha1);

        String parentDomain;
        try {
          parentDomain = MessageId.parse(((PktMessage) pkt).getCatEventID()).getDomain();
        } catch (Exception e) {
          parentDomain = "UnknownDomain";
        }
        //            MessageTree tree = Cat.getManager().getThreadLocalMessageTree();
        //            tree.setMessageId(((PktMessage)pkt).getCatEventID());

        Transaction producerServerTransaction =
            Cat.getProducer()
                .newTransaction(
                    "In:" + topicName, parentDomain + ":" + swallowMessage.getSourceIp());
        // 将swallowMessage保存到mongodb
        try {
          messageDAO.saveMessage(topicName, swallowMessage);
          producerServerTransaction.addData("sha1", swallowMessage.getSha1());
          producerServerTransaction.setStatus(Message.SUCCESS);
        } catch (Exception e) {
          producerServerTransaction.addData(swallowMessage.toKeyValuePairs());
          producerServerTransaction.setStatus(e);
          Cat.getProducer().logError(e);
          LOGGER.error("[Save message to DB failed.]", e);
          throw new ServerDaoException(e);
        } finally {
          producerServerTransaction.complete();
        }
        break;
      default:
        LOGGER.warn("[Received unrecognized packet.]" + pkt);
        break;
    }
    return pktRet;
  }