Beispiel #1
0
 protected boolean isEqual(Network info1, Network info2) {
   if (info1 == null && info2 == null) {
     return true;
   } else {
     return info1.toString().equals(info2.toString());
   }
 }
Beispiel #2
0
  @Test
  public void testGetValidNetworkCountByStage() {
    init();

    List<Network> infosOfDB = readDBByUserId(_info.getUserId());
    int countOfDB = 0;
    for (int i = 0; i < infosOfDB.size(); i++) {
      if (infosOfDB.get(i).getStatus() == -1 || infosOfDB.get(i).getStatus() == 0) {
        countOfDB++;
      }
    }
    int countOfOrigin = 0;
    for (int i = 0; i < _infos.size(); i++) {
      if (_infos.get(i).getStatus() == -1 || _infos.get(i).getStatus() == 0) {
        countOfOrigin++;
      }
    }
    int countOfCache =
        AdapterFactory.getNetworkAdapter()
            .getValidNetworkCountByStage(_info.getUserId(), _info.getStage());
    int countOfReaderCache =
        AdapterFactory.getNetworkReaderAdapter()
            .getValidNetworkCountByStage(_info.getUserId(), _info.getStage());

    System.out.println(
        countOfOrigin + " " + countOfDB + " " + countOfCache + " " + countOfReaderCache);
    Assert.assertEquals(countOfOrigin, countOfDB);
    Assert.assertEquals(countOfOrigin, countOfCache);
    Assert.assertEquals(countOfOrigin, countOfReaderCache);
  }
Beispiel #3
0
  @Test
  public void testGetNetworkList() {
    init();

    Network info = genInfoCopy(1);
    setDBAndInfos(info.getId(), info);
    AdapterFactory.getNetworkAdapter().reloadNetworkList(_info.getUserId());
    checkAll();
  }
Beispiel #4
0
  @Test
  public void testReloadNetworkList() {
    init();

    AdapterFactory.getNetworkAdapter().reloadNetworkList(_info.getUserId());
    checkAll();

    // Writer
    init();

    AdapterFactory.getNetworkWriterAdapter().reloadNetworkList(_info.getUserId());
    checkAll();
  }
Beispiel #5
0
  @Test
  public void testGetNetwork() {
    init();

    Network infoOfDB = readDBByInfoId(_info.getNetworkId()).get(0);
    Network infoOfCache =
        AdapterFactory.getNetworkAdapter().getNetwork(_info.getUserId(), _info.getNetworkId());
    Network infoOfReaderCache =
        AdapterFactory.getNetworkReaderAdapter()
            .getNetwork(_info.getUserId(), _info.getNetworkId());

    Assert.assertTrue(isEqual(infoOfDB, _info));
    Assert.assertTrue(isEqual(infoOfCache, _info));
    Assert.assertTrue(isEqual(infoOfReaderCache, _info));
  }
Beispiel #6
0
  @Test
  public void testRemoveNetwork() {
    init();

    _infos.remove(_info);
    AdapterFactory.getNetworkAdapter().removeNetwork(_info.getUserId(), _info.getNetworkId());
    checkAll();

    // Writer
    init();

    _infos.remove(_info);
    AdapterFactory.getNetworkWriterAdapter().removeNetwork(_info.getUserId(), _info.getNetworkId());
    checkAll();
  }
Beispiel #7
0
  @Test
  public void testGetNetworkListByStatusIntInt() {
    init();

    List<Network> infosOfDB = readDBByUserId(_info.getUserId());
    List<Network> infosOfCache =
        AdapterFactory.getNetworkAdapter()
            .getNetworkListByStatus(_info.getUserId(), _info.getStatus());
    List<Network> infosOfReaderCache =
        AdapterFactory.getNetworkReaderAdapter()
            .getNetworkListByStatus(_info.getUserId(), _info.getStatus());

    Assert.assertTrue(isEqual(infosOfDB, _infos));
    Assert.assertTrue(isEqual(infosOfCache, _infos));
    Assert.assertTrue(isEqual(infosOfReaderCache, _infos));
  }
Beispiel #8
0
  /** reload和get是最关键的方法 测试中对缓存的控制依赖于reload方法 测试中对缓存的判断依赖于get方法 */
  @Test
  public void testBase() {
    init();

    // Debug info
    List<Network> infosOfDB = readDBByUserId(_info.getUserId());
    List<Network> infosOfCache =
        AdapterFactory.getNetworkAdapter().getNetworkList(_info.getUserId());
    List<Network> infosOfReaderCache =
        AdapterFactory.getNetworkReaderAdapter().getNetworkList(_info.getUserId());
    System.out.println(infosOfDB);
    System.out.println(infosOfCache);
    System.out.println(infosOfReaderCache);

    checkAll();
  }
Beispiel #9
0
 protected boolean isDBCorrect() {
   List<Network> infosOfDB = readDBByUserId(_info.getUserId());
   System.out.println("\ninfosOfDB:");
   System.out.println("--------------------------------");
   System.out.println(infosOfDB);
   return isEqual(infosOfDB, _infos);
 }
Beispiel #10
0
  @Test
  public void testGetNetworkCountByStage() {
    init();

    int countOfDB = readDBByUserId(_info.getUserId()).size();
    int countOfCache =
        AdapterFactory.getNetworkAdapter()
            .getNetworkCountByStage(_info.getUserId(), _info.getStage());
    int countOfReaderCache =
        AdapterFactory.getNetworkReaderAdapter()
            .getNetworkCountByStage(_info.getUserId(), _info.getStage());
    int countOfOrigin = _infos.size();

    Assert.assertEquals(countOfOrigin, countOfDB);
    Assert.assertEquals(countOfOrigin, countOfCache);
    Assert.assertEquals(countOfOrigin, countOfReaderCache);
  }
Beispiel #11
0
 protected boolean isReaderCacheCorrect() {
   List<Network> infosOfReaderCache =
       AdapterFactory.getNetworkReaderAdapter().getNetworkList(_info.getUserId());
   System.out.println("\ninfosOfReaderCache:");
   System.out.println("--------------------------------");
   System.out.println(infosOfReaderCache);
   return isEqual(infosOfReaderCache, _infos);
 }
Beispiel #12
0
  /** ((networkId >= 60000000) && (networkId <= 70000000) && ((status == 0) || (status == -1))) */
  @Test
  public void testGetRegionalNetwork() {
    init();
    List<Network> all = readDBByRecordId(_info.getId());
    Network infoOfDB = null;
    for (int i = 0; i < all.size(); i++) {
      if (all.get(i).getNetworkId() >= 60000000
          && all.get(i).getNetworkId() <= 70000000
          && (all.get(i).getStatus() == 0 || all.get(i).getStatus() == -1)) {
        infoOfDB = all.get(i);
      }
    }
    Network infoOfOrigin = null;
    if (_info.getNetworkId() >= 60000000
        && _info.getNetworkId() <= 70000000
        && (_info.getStatus() == 0 || _info.getStatus() == -1)) {
      infoOfOrigin = _info;
    }

    Network infoOfCache = AdapterFactory.getNetworkAdapter().getRegionalNetwork(_info.getUserId());
    Network infoOfReaderCache =
        AdapterFactory.getNetworkReaderAdapter().getRegionalNetwork(_info.getUserId());

    System.out.println(
        infoOfOrigin
            + "\n---\n"
            + infoOfDB
            + "\n---\n"
            + infoOfCache
            + "\n---\n"
            + infoOfReaderCache);
    Assert.assertTrue(isEqual(infoOfDB, infoOfOrigin));
    Assert.assertTrue(isEqual(infoOfCache, infoOfOrigin));
    Assert.assertTrue(isEqual(infoOfReaderCache, infoOfOrigin));
  }
Beispiel #13
0
  @Test
  public void testGetNetworkListByStageAndStatus() {
    init();
    Network info = genInfoCopy(1);
    int status[] = {_info.getStatus(), info.getStatus()};
    setDBAndInfos(info.getId(), info);
    AdapterFactory.getNetworkAdapter().reloadNetworkList(_info.getUserId());

    List<Network> infosOfDB = readDBByUserId(_info.getUserId());
    List<Network> infosOfCache =
        AdapterFactory.getNetworkAdapter()
            .getNetworkListByStageAndStatus(_info.getUserId(), _info.getStage(), status);
    List<Network> infosOfReaderCache =
        AdapterFactory.getNetworkReaderAdapter()
            .getNetworkListByStageAndStatus(_info.getUserId(), _info.getStage(), status);

    Assert.assertTrue(isEqual(infosOfDB, _infos));
    Assert.assertTrue(isEqual(infosOfCache, _infos));
    Assert.assertTrue(isEqual(infosOfReaderCache, _infos));
  }
Beispiel #14
0
  @Test
  public void testSetNetwork() {
    Network info = genInfoCopy(0);

    init();

    setDBAndInfos(info.getId(), info);
    AdapterFactory.getNetworkAdapter().reloadNetworkList(_info.getUserId());

    _infos.remove(_info);
    AdapterFactory.getNetworkAdapter().setNetwork(info);
    checkAll();

    // Writer
    init();

    setDBAndInfos(info.getId(), info);
    AdapterFactory.getNetworkAdapter().reloadNetworkList(_info.getUserId());

    _infos.remove(_info);
    AdapterFactory.getNetworkWriterAdapter().setNetwork(info);
    checkAll();
  }
Beispiel #15
0
  @Test
  public void testIsExistInNetwork() {
    init();

    Network infoOfDB = readDBByInfoId(_info.getNetworkId()).get(0);
    boolean isExistInInfo = _info.getStatus() <= 0;
    boolean isExistInDB = infoOfDB.getStatus() <= 0;
    boolean isExistInCache =
        AdapterFactory.getNetworkAdapter()
            .isExistInNetwork(_info.getUserId(), _info.getNetworkId());
    boolean isExistInReaderCache =
        AdapterFactory.getNetworkReaderAdapter()
            .isExistInNetwork(_info.getUserId(), _info.getNetworkId());

    Assert.assertEquals(isExistInDB, isExistInInfo);
    Assert.assertEquals(isExistInCache, isExistInInfo);
    Assert.assertEquals(isExistInReaderCache, isExistInInfo);
  }
Beispiel #16
0
 protected List<Network> readDB(String sql) {
   List<Network> result = new ArrayList<Network>();
   try {
     Connection c = XceAdapter.getInstance().getReadConnection("common");
     try {
       Statement s = c.createStatement();
       try {
         ResultSet rs = s.executeQuery(sql);
         while (rs.next()) {
           Network info = new Network();
           info.setId(rs.getInt("id"));
           info.setUserId(rs.getInt("userid"));
           info.setStage(rs.getInt("stage"));
           info.setNetworkId(rs.getInt("network_id"));
           info.setNetworkName(rs.getString("network_name"));
           info.setInfoId(rs.getInt("info_id"));
           info.setJoinTime(DateFormatter.parse(rs.getString("join_time")));
           info.setStatus(rs.getInt("status"));
           result.add(info);
         }
         rs.close();
       } catch (Exception e) {
         e.printStackTrace();
         Assert.assertFalse(true);
       } finally {
         s.close();
       }
     } catch (Exception e) {
       e.printStackTrace();
       Assert.assertFalse(true);
     } finally {
       c.close();
     }
   } catch (Exception e) {
     e.printStackTrace();
     Assert.assertFalse(true);
   }
   return result;
 }
Beispiel #17
0
 public NetworkTestCase(
     int id,
     int userId,
     int stage,
     int networkId,
     String networkName,
     int infoId,
     String joinTime,
     int status) {
   _info = new Network();
   _info.setId(id);
   _info.setUserId(userId);
   _info.setStage(stage);
   _info.setNetworkId(networkId);
   _info.setNetworkName(networkName);
   _info.setInfoId(infoId);
   _info.setJoinTime(DateFormatter.parse(joinTime));
   _info.setStatus(status);
   _infos = new ArrayList<Network>();
 }
Beispiel #18
0
 protected void setDBAndInfos(int recordId, Network info) {
   String sql =
       "replace into network_history(id,userid,stage,network_id,network_name,info_id,join_time,status) values ("
           + recordId
           + ","
           + info.getUserId()
           + ","
           + info.getStage()
           + ","
           + info.getNetworkId()
           + ",'"
           + info.getNetworkName()
           + "',"
           + info.getInfoId()
           + ",'"
           + DateFormatter.format(info.getJoinTime())
           + "',"
           + info.getStatus()
           + ")";
   writeDB(sql);
   _infos.add(info);
 }
Beispiel #19
0
 /** 初始化过程: 1. 清理DB/Cache/_infos; 2. 初始化DB/Cache/_infos. */
 protected void init() {
   cleanBbAndCache();
   _infos.clear();
   setDBAndInfos(_info.getId(), _info);
   AdapterFactory.getNetworkAdapter().reloadNetworkList(_info.getUserId());
 }
Beispiel #20
0
 protected void cleanBbAndCache() {
   cleanDBByUserId(_info.getUserId());
   AdapterFactory.getNetworkAdapter().reloadNetworkList(_info.getUserId());
 }
Beispiel #21
0
  /**
   * 获取一份新的数据
   *
   * @param idStep
   * @return
   */
  protected Network genInfoCopy(int idStep) {
    Network result = new Network();
    result.setId(_info.getId() + idStep);
    result.setUserId(_info.getUserId());
    result.setStage(_info.getStage());
    result.setNetworkId(_info.getNetworkId() + idStep);
    result.setNetworkName(_info.getNetworkName() + ".new");
    result.setInfoId(_info.getInfoId());
    result.setJoinTime(_info.getJoinTime());
    result.setStatus(_info.getStatus() + idStep);

    return result;
  }