Example #1
0
  public void testArchivedStorage()
      throws MalformedURLException, CoreException, IOException, NoSuchFieldException,
          IllegalArgumentException, IllegalAccessException, NoSuchMethodException,
          InvocationTargetException {
    IssueStorage storage = IssueStorage.getInstance();
    long ts = System.currentTimeMillis();
    String id1 = "id1";
    String id2 = "id2";

    String url = "http://test/bugzilla";
    String qName = "SomeQuery";

    storage.storeArchivedQueryIssues(url, qName, new String[] {id1, id2});
    Map<String, Long> read = storage.readArchivedQueryIssues(url, qName);

    assertEquals(2, read.size());
    assertTrue(ts <= read.get(id1));
    assertTrue(ts <= read.get(id2));

    // wait a sec and set TTL so that the archived issues shuld be cleaned up
    try {
      Thread.currentThread().sleep(1000);
    } catch (InterruptedException ex) {
      Exceptions.printStackTrace(ex);
    }
    Field f = BugtrackingConfig.class.getDeclaredField("DEFAULT_ARCHIVED_TTL");
    f.setAccessible(true);
    f.set(BugtrackingConfig.getInstance(), new Long(0)); // zero time to live

    read = storage.readArchivedQueryIssues(url, qName);
    assertEquals(0, read.size());
  }
Example #2
0
  public void testCleanup()
      throws MalformedURLException, CoreException, IOException, NoSuchFieldException,
          IllegalArgumentException, IllegalAccessException, NoSuchMethodException,
          InvocationTargetException {
    IssueStorage storage = IssueStorage.getInstance();
    long ts = System.currentTimeMillis();
    Map<String, String> attr = new HashMap<String, String>();
    String id1 = "id1";
    String id2 = "id2";

    String url = "http://test/bugzilla";
    String qName = "SomeQuery";

    DummyIssue i1 = new DummyIssue(id1, attr);
    DummyIssue i2 = new DummyIssue(id2, attr);

    long lm = System.currentTimeMillis();
    IssueCache<DummyIssue, Object> cache = getCache();
    IssueEntry ie1 = cache.new IssueEntry(i1, i1.id, attr, -1, -1, false, lm);
    IssueEntry ie2 = cache.new IssueEntry(i2, i2.id, attr, -1, -1, false, lm);

    storage.storeIssue(url, ie1);
    storage.storeIssue(url, ie2);

    // store query
    storage.storeQuery(url, qName, new String[] {id1, id2});
    List<String> stored = storage.readQuery(url, qName);

    assertEquals(2, stored.size());
    File folder = getNameSpaceFolder(url);
    File[] issueFiles =
        folder.listFiles(
            new FilenameFilter() {
              public boolean accept(File dir, String name) {
                return name.endsWith(".i");
              }
            });
    assertEquals(2, issueFiles.length); // issues are there

    // cleanup, yet issues are living in a stored query
    storage.cleanup();
    issueFiles =
        folder.listFiles(
            new FilenameFilter() {
              public boolean accept(File dir, String name) {
                return name.endsWith(".i");
              }
            });
    assertEquals(2, issueFiles.length); // issues are still there

    // cleanup, yet issues are living in archive
    storage.storeQuery(url, qName, new String[] {});
    storage.storeArchivedQueryIssues(url, qName, new String[] {id1, id2});
    storage.cleanup();
    issueFiles =
        folder.listFiles(
            new FilenameFilter() {
              public boolean accept(File dir, String name) {
                return name.endsWith(".i");
              }
            });
    assertEquals(2, issueFiles.length); // issues are still there

    // cleanup, issues aren't in a query or archived
    storage.storeQuery(url, qName, new String[] {});
    storage.storeArchivedQueryIssues(url, qName, new String[] {});
    storage.cleanup();
    issueFiles =
        folder.listFiles(
            new FilenameFilter() {
              public boolean accept(File dir, String name) {
                return name.endsWith(".i");
              }
            });
    assertEquals(0, issueFiles.length); // issues are still there
  }