Search in sources :

Example 1 with FileStatusInternal

use of org.smartdata.server.metastore.FileStatusInternal in project SSM by Intel-bigdata.

the class TestRuleManager method testMultiThreadChangeState.

@Test
public void testMultiThreadChangeState() throws Exception {
    String rule = "file: every 1s \n | length > 10 | cachefile";
    long now = System.currentTimeMillis();
    long length = 100;
    long fid = 10000;
    FileStatusInternal[] files = { new FileStatusInternal(length, false, 3, 1024, now, now, null, null, null, null, "testfile".getBytes(), "/tmp", fid, 0, null, (byte) 3) };
    dbAdapter.insertFiles(files);
    long rid = ruleManager.submitRule(rule, RuleState.ACTIVE);
    long start = System.currentTimeMillis();
    int nThreads = 10;
    Thread[] threads = new Thread[nThreads];
    for (int i = 0; i < nThreads; i++) {
        threads[i] = new Thread(new StateChangeWorker(rid));
    }
    for (Thread t : threads) {
        t.start();
    }
    for (Thread t : threads) {
        t.join();
    }
    long end = System.currentTimeMillis();
    System.out.println("Time used = " + (end - start) + " ms");
    // This is needed due to async threads
    Thread.sleep(1000);
    RuleInfo res = ruleManager.getRuleInfo(rid);
    System.out.println(res);
    Thread.sleep(5000);
    RuleInfo after = ruleManager.getRuleInfo(rid);
    System.out.println(after);
    if (res.getState() == RuleState.ACTIVE) {
        Assert.assertTrue(after.getNumCmdsGen() - res.getNumCmdsGen() <= 6);
    } else {
        Assert.assertTrue(after.getNumCmdsGen() == res.getNumCmdsGen());
    }
}
Also used : FileStatusInternal(org.smartdata.server.metastore.FileStatusInternal) RuleInfo(org.smartdata.common.rule.RuleInfo) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 RuleInfo (org.smartdata.common.rule.RuleInfo)1 FileStatusInternal (org.smartdata.server.metastore.FileStatusInternal)1