Package com.taobao.tddl.jdbc.group

Examples of com.taobao.tddl.jdbc.group.TGroupDataSource


    GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(2);
    clearData(tddlJT, sql, new Object[] { RANDOM_ID });
  }

  protected static JdbcTemplate getJT(String dbGroupKey) {
    tds = new TGroupDataSource();
    tds.setAppName(APPNAME);
    tds.setDbGroupKey(dbGroupKey);
    tds.init();
    return new JdbcTemplate(tds);
  }
View Full Code Here


  @Test
  public void switching() throws Exception {
    if (true)
      return; //Ҫ�ֹ�����ע�͵���һ��

    TGroupDataSource ds = new TGroupDataSource(dbGroupKey, appName);
    ds.setAutoSelectWriteDataSource(true);
    ds.init();

    Connection conn = ds.getConnection();
    Statement stmt = conn.createStatement();

    //�����������һ����¼
    assertEquals(stmt.executeUpdate("insert into crud(f1,f2) values(10,'str')"), 1);

    System.out.println("�����������һ����¼...");

    System.out.println("�������״̬�ij�NA����Ϣһ�ְ���..."); //ͬʱ��ر�MySQL���ݿ������
    Thread.sleep(90 * 1000);
    try {
      stmt.executeUpdate("update crud set f2='str2'");
      fail("���⴦��NA״̬���ܽ��и��²���");
    } catch (Exception e) {
      System.out.println("���⵱ǰ����NA״̬���޷����и��²�����Exception: " + e);

      System.out.println("�ؽ�Connection"); //���ܻ���ԭ��Connection�ؽ�Statement
      conn = ds.getConnection();
      System.out.println("�ؽ�Statement");
      stmt = conn.createStatement();
    }

    System.out.println("�ѱ�1��״̬�ij�RW����Ϣ�����...");
View Full Code Here

  //dbGroup: db1:w, db2:r20, db3:r30
  @Test
  public void testWRR() throws Exception {
    MockServer.setConfigInfo(TGroupDataSource.getFullDbGroupKey(dbGroupKey), "db1:w, db2:r20, db3:r30");
    ds = new TGroupDataSource(dbGroupKey, appName);
    ds.init();
    Connection conn = ds.getConnection();

   
    Statement stmt = conn.createStatement();
View Full Code Here

  }

  @Test
  public void testThreadLocalDataSourceIndex() throws Exception {
    try {
      TGroupDataSource ds = new TGroupDataSource(dbGroupKey, appName);
      ds.init();
     
      ThreadLocalMap.put(ThreadLocalString.DATASOURCE_INDEX, 0);
      Connection conn = ds.getConnection();
      Statement stmt = conn.createStatement();
      assertEquals(stmt.executeUpdate("insert into crud(f1,f2) values(100,'str')"), 1);
      ResultSet rs = stmt.executeQuery("select f1,f2 from crud where f1=100");
      assertTrue(rs.next());
View Full Code Here

  }
 
  @Test
  public void testGroupDataSourceRouteHelper() throws Exception{
    try {
      TGroupDataSource ds = new TGroupDataSource(dbGroupKey, appName);
      ds.init();
     
      GroupDataSourceRouteHelper.executeByGroupDataSourceIndex(0);
      Connection conn = ds.getConnection();
      Statement stmt = conn.createStatement();
      assertEquals(stmt.executeUpdate("insert into crud(f1,f2) values(100,'str')"), 1);
      ResultSet rs = stmt.executeQuery("select f1,f2 from crud where f1=100");
      assertTrue(rs.next());
View Full Code Here

    DataSource ds3 = DataSourceFactory.getMySQLDataSource(3);

    Connection conn = null;
    Statement stmt = null;

    TGroupDataSource ds = new TGroupDataSource();
    DataSourceWrapper dsw = new DataSourceWrapper("db1", "rw", ds1, DBType.MYSQL);
    ds.init(dsw);

    conn = ds.getConnection();
    stmt = conn.createStatement();
    stmt.executeUpdate("delete from crud");
    stmt.close();
    conn.close();

    ds = new TGroupDataSource();
    dsw = new DataSourceWrapper("db2", "rw", ds2, DBType.MYSQL);
    ds.init(dsw);
    conn = ds.getConnection();
    stmt = conn.createStatement();
    stmt.executeUpdate("delete from crud");
    stmt.close();
    conn.close();

    ds = new TGroupDataSource();
    dsw = new DataSourceWrapper("db3", "rw", ds3, DBType.MYSQL);
    ds.init(dsw);
    conn = ds.getConnection();
    stmt = conn.createStatement();
    stmt.executeUpdate("delete from crud");
    stmt.close();
    conn.close();
  }
View Full Code Here

  public void ����ִ�ж���߳�_�漰TAtomDataSource() throws Exception {
    int size = 3;
    MyThread[] myThreads = new MyThread[size];
    for (int i = 1; i <= size; i++) {

      MyThread t = new MyThread(new TGroupDataSource("myDbGroupKey" + i, appName));
      t.start();
      myThreads[i-1] = t;
    }
   
    for (int i = 1; i <= size; i++) {
View Full Code Here

 
  @Test
  public void ����ִ�ж���߳�_�漰TAtomDataSource() throws Exception {
    int size = 3;
    for (int i = 1; i <= size; i++) {
      MyThread t = new MyThread(new TGroupDataSource("myDbGroupKey" + i, appName));
      t.start();
      t.join();
    }
  }
View Full Code Here

  TGroupDataSource ds;

  @Test(expected = TGroupDataSourceException.class)
  public void û������DbGroupKey() {
    ds = new TGroupDataSource();
    ds.init();
  }
View Full Code Here

    ds.init();
  }
 
  @Test(expected = TGroupDataSourceException.class)
  public void û������appName() {
    ds = new TGroupDataSource();
    ds.init();
  }
View Full Code Here

TOP

Related Classes of com.taobao.tddl.jdbc.group.TGroupDataSource

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.