Search in sources :

Example 6 with FilePositionResult

use of com.linkedin.databus.core.TrailFilePositionSetter.FilePositionResult in project databus by linkedin.

the class TestTrailFilePositionSetter method testRequestedScnOlderThanOldestTransaction.

/**
   * Verify that requesting an SCN that's older than the oldest trail file causes ERROR
   * to be returned.  Also check various valid states:  SCN that isn't the max for its
   * transaction; SCN that is the max for its transaction; earliest SCN; etc.
   */
@Test
public void testRequestedScnOlderThanOldestTransaction() throws Exception {
    final Logger log = Logger.getLogger("TestTrailFilePositionSetter.testRequestedScnOlderThanOldestTransaction");
    //log.setLevel(Level.DEBUG);
    log.info("starting");
    File dir = createTempDir();
    // first SCN is hardcoded always to be 100:
    createTrailFiles(dir.getAbsolutePath(), TRAIL_FILENAME_PREFIX, 150, /* numTxns, 24 lines each */
    1250, /* numLinesPerFile */
    1, /* numLinesPerNewline */
    "\n", 0, -1, /* no corruption */
    "", false, "");
    TrailFilePositionSetter posSetter = new TrailFilePositionSetter(dir.getAbsolutePath(), TRAIL_FILENAME_PREFIX);
    GGXMLTrailTransactionFinder finder = new GGXMLTrailTransactionFinder();
    FilePositionResult res;
    // SCN 99 is before the earliest SCN present in the trail files (100), so expect ERROR:
    res = posSetter.locateFilePosition(99, finder);
    Assert.assertEquals(res.getStatus(), FilePositionResult.Status.ERROR, "expected error for exact-match SCN that's too old.");
    // "Transaction-SCN" semantics:  max SCN is 121 in this transaction and 119 in the
    // previous one, so those are the values used for most of the "is it found?" logic.
    // Since 120 falls between the two but doesn't equal either one, it's not considered
    // to be found exactly (even though it's actually present), but the state is still
    // valid, so processing can continue (i.e., it doesn't matter).
    finder.reset();
    res = posSetter.locateFilePosition(120, finder);
    assertFilePositionResult(res, dir, 120, FilePositionResult.Status.EXACT_SCN_NOT_FOUND);
    // For SCN <= the earliest transactions maxSCN, we throw error
    finder.reset();
    res = posSetter.locateFilePosition(100, finder);
    Assert.assertEquals(res.getStatus(), FilePositionResult.Status.ERROR, "expected error for exact-match SCN that's too old.");
    // Related, weird corner case:  USE_EARLIEST_SCN uses the min SCN in the oldest transaction,
    // so even though an exact match for 100 doesn't return FOUND, this does:
    finder.reset();
    res = posSetter.locateFilePosition(TrailFilePositionSetter.USE_EARLIEST_SCN, finder);
    assertFilePositionResult(res, dir, 100, FilePositionResult.Status.FOUND);
    // For SCN <= the earliest transactions maxSCN, we throw error
    finder.reset();
    res = posSetter.locateFilePosition(101, finder);
    Assert.assertEquals(res.getStatus(), FilePositionResult.Status.ERROR, "expected error for exact-match SCN that's too old.");
    log.info(DONE_STRING);
}
Also used : GGXMLTrailTransactionFinder(com.linkedin.databus2.producers.db.GGXMLTrailTransactionFinder) Logger(org.apache.log4j.Logger) File(java.io.File) FilePositionResult(com.linkedin.databus.core.TrailFilePositionSetter.FilePositionResult) Test(org.testng.annotations.Test)

Example 7 with FilePositionResult

use of com.linkedin.databus.core.TrailFilePositionSetter.FilePositionResult in project databus by linkedin.

the class TestTrailFilePositionSetter method testFailureMode_MalformedFirstTransactionInFirstFile.

/**
   * Verify that corruption that occurs early in the file causes USE_EARLIEST_SCN to return the
   * first SCN of the first uncorrupted transaction.
   */
@Test
public void testFailureMode_MalformedFirstTransactionInFirstFile() throws Exception {
    final Logger log = Logger.getLogger("TestTrailFilePositionSetter.testFailureMode_MalformedFirstTransactionInFirstFile");
    log.info("starting");
    File dir = createTempDir();
    // first SCN is hardcoded always to be 100
    createTrailFiles(dir.getAbsolutePath(), TRAIL_FILENAME_PREFIX, 150, /* numTxns, 24 lines each */
    1250, /* numLinesPerFile */
    1, /* numLinesPerNewline */
    "\n", 0, 100, /* corrupt first SCN */
    "xyzzy", false, "");
    TrailFilePositionSetter posSetter = new TrailFilePositionSetter(dir.getAbsolutePath(), TRAIL_FILENAME_PREFIX);
    GGXMLTrailTransactionFinder finder = new GGXMLTrailTransactionFinder();
    FilePositionResult res;
    // SCN 100 is corrupted, so 101 is the effective oldest SCN => 100 treated as error:
    res = posSetter.locateFilePosition(100, finder);
    Assert.assertEquals(res.getStatus(), FilePositionResult.Status.ERROR, "expected error for exact-match SCN that's corrupted and oldest in all trail files.");
    // SCN 101 is OK (regexQuery() doesn't fully validate XML):
    finder.reset();
    res = posSetter.locateFilePosition(TrailFilePositionSetter.USE_EARLIEST_SCN, finder);
    assertFilePositionResult(res, dir, 101, FilePositionResult.Status.FOUND);
    log.info(DONE_STRING);
}
Also used : GGXMLTrailTransactionFinder(com.linkedin.databus2.producers.db.GGXMLTrailTransactionFinder) Logger(org.apache.log4j.Logger) File(java.io.File) FilePositionResult(com.linkedin.databus.core.TrailFilePositionSetter.FilePositionResult) Test(org.testng.annotations.Test)

Example 8 with FilePositionResult

use of com.linkedin.databus.core.TrailFilePositionSetter.FilePositionResult in project databus by linkedin.

the class TestTrailFilePositionSetter method testScnPositionSetter.

private void testScnPositionSetter(int startLine, int startScn, int endScn, int beginFoundScn, Logger log) throws Exception {
    String[] newLines = { "\n", "\r", "\r\n" };
    for (String newLine : newLines) {
        File dir = createTempDir();
        createTrailFiles(dir.getAbsolutePath(), TRAIL_FILENAME_PREFIX, startScn, endScn, 1, newLine, startLine, -1, "", false, "");
        log.info("Directory is: " + dir);
        TrailFilePositionSetter posSetter = null;
        //GoldenGateTransactionSCNFinder finder = new GoldenGateTransactionSCNFinder();
        GGXMLTrailTransactionFinder finder = new GGXMLTrailTransactionFinder();
        //less than minScn
        for (long i = 0; i < beginFoundScn; i++) {
            posSetter = new TrailFilePositionSetter(dir.getAbsolutePath(), TRAIL_FILENAME_PREFIX);
            Logger log2 = posSetter._log;
            log2.setLevel(Level.INFO);
            log2.info("Created a TrailFilePositionSetter with suffix x3");
            //finder = new GoldenGateTransactionSCNFinder();
            finder = new GGXMLTrailTransactionFinder();
            FilePositionResult res = posSetter.getFilePosition(i, finder);
            Assert.assertEquals(res.getStatus(), FilePositionResult.Status.ERROR, "Result Status for SCN: " + i + ", Result: " + res);
        }
        //Found Case
        for (long i = beginFoundScn; i < (startScn + endScn); i++) {
            posSetter = new TrailFilePositionSetter(dir.getAbsolutePath(), TRAIL_FILENAME_PREFIX);
            //finder = new GoldenGateTransactionSCNFinder();
            finder = new GGXMLTrailTransactionFinder();
            FilePositionResult res = posSetter.getFilePosition(i, finder);
            log.info("For scn (" + i + "):  the result is:  " + res);
            if (i % 2 == 0)
                assertFilePositionResult(res, dir, i + 1, FilePositionResult.Status.EXACT_SCN_NOT_FOUND);
            else
                assertFilePositionResult(res, dir, i, FilePositionResult.Status.FOUND);
        }
        //Found Case
        for (long i = (startScn + endScn); i < (startScn + endScn) + 20; i++) {
            posSetter = new TrailFilePositionSetter(dir.getAbsolutePath(), TRAIL_FILENAME_PREFIX);
            //finder = new GoldenGateTransactionSCNFinder();
            finder = new GGXMLTrailTransactionFinder();
            FilePositionResult res = posSetter.getFilePosition(i, finder);
            log.info("For scn (" + i + "):  the result is:  " + res);
            assertFilePositionResult(res, dir, 299, FilePositionResult.Status.EXACT_SCN_NOT_FOUND);
        }
    }
}
Also used : GGXMLTrailTransactionFinder(com.linkedin.databus2.producers.db.GGXMLTrailTransactionFinder) Logger(org.apache.log4j.Logger) File(java.io.File) FilePositionResult(com.linkedin.databus.core.TrailFilePositionSetter.FilePositionResult)

Example 9 with FilePositionResult

use of com.linkedin.databus.core.TrailFilePositionSetter.FilePositionResult in project databus by linkedin.

the class TestTrailFilePositionSetter method testScnPositionLocator.

private void testScnPositionLocator(int startLine, int startScn, int endScn, int beginFoundScn, Logger log) throws Exception {
    File dir = createTempDir();
    // TODO/FIXME:  why are startScn and endScn being used for numTxns and numLinesPerFile, respectively?
    createTrailFiles(dir.getAbsolutePath(), TRAIL_FILENAME_PREFIX, startScn, endScn, 1, "\n", startLine, -1, "", false, "");
    log.info("Directory is: " + dir);
    TrailFilePositionSetter posSetter = null;
    //GoldenGateTransactionSCNFinder finder;
    GGXMLTrailTransactionFinder finder;
    //less than minScn
    for (long i = 0; i < beginFoundScn; i++) {
        posSetter = new TrailFilePositionSetter(dir.getAbsolutePath(), TRAIL_FILENAME_PREFIX);
        //finder = new GoldenGateTransactionSCNFinder();
        finder = new GGXMLTrailTransactionFinder();
        FilePositionResult res = posSetter.locateFilePosition(i, finder);
        Assert.assertEquals(res.getStatus(), FilePositionResult.Status.ERROR, "Result Status for SCN: " + i + ", Result: " + res);
    }
    //Found Case
    for (long i = beginFoundScn; i < (startScn + endScn); i++) {
        posSetter = new TrailFilePositionSetter(dir.getAbsolutePath(), TRAIL_FILENAME_PREFIX);
        //finder = new GoldenGateTransactionSCNFinder();
        finder = new GGXMLTrailTransactionFinder();
        FilePositionResult res = posSetter.locateFilePosition(i, finder);
        log.info("For scn (" + i + "):  the result is:  " + res);
        if (i % 2 == 0)
            assertFilePositionResult(res, dir, i + 1, FilePositionResult.Status.EXACT_SCN_NOT_FOUND);
        else
            assertFilePositionResult(res, dir, i, FilePositionResult.Status.FOUND);
    }
    //Found Case
    for (long i = (startScn + endScn); i < (startScn + endScn) + 20; i++) {
        posSetter = new TrailFilePositionSetter(dir.getAbsolutePath(), TRAIL_FILENAME_PREFIX);
        //finder = new GoldenGateTransactionSCNFinder();
        finder = new GGXMLTrailTransactionFinder();
        FilePositionResult res = posSetter.locateFilePosition(i, finder);
        log.info("For scn (" + i + "):  the result is:  " + res);
        assertFilePositionResult(res, dir, 299, FilePositionResult.Status.EXACT_SCN_NOT_FOUND);
    }
}
Also used : GGXMLTrailTransactionFinder(com.linkedin.databus2.producers.db.GGXMLTrailTransactionFinder) File(java.io.File) FilePositionResult(com.linkedin.databus.core.TrailFilePositionSetter.FilePositionResult)

Example 10 with FilePositionResult

use of com.linkedin.databus.core.TrailFilePositionSetter.FilePositionResult in project databus by linkedin.

the class TestTrailFilePositionSetter method testDeletedDirectory.

/**
   * DDSDBUS-2603 NUllPointerException in GG Relay in Experimental CLuster
   * @throws Exception
   */
@Test
public void testDeletedDirectory() throws Exception {
    final Logger log = Logger.getLogger("TestTrailFilePositionSetter.testDeletedDirectory");
    log.info("starting");
    File dir = createTempDir();
    TrailFilePositionSetter posSetter = new TrailFilePositionSetter(dir.getAbsolutePath(), TRAIL_FILENAME_PREFIX);
    GGXMLTrailTransactionFinder finder = new GGXMLTrailTransactionFinder();
    // Now delete the directory to make the locateFilePosition() see null for listFiles() call.
    boolean deleted = dir.delete();
    Assert.assertTrue(deleted, "Deleted the trail directory successfully");
    FilePositionResult res = posSetter.locateFilePosition(100, finder);
    Assert.assertEquals(res.getStatus(), Status.NO_TXNS_FOUND, "File Position Result Status");
    log.info(DONE_STRING);
}
Also used : GGXMLTrailTransactionFinder(com.linkedin.databus2.producers.db.GGXMLTrailTransactionFinder) Logger(org.apache.log4j.Logger) File(java.io.File) FilePositionResult(com.linkedin.databus.core.TrailFilePositionSetter.FilePositionResult) Test(org.testng.annotations.Test)

Aggregations

FilePositionResult (com.linkedin.databus.core.TrailFilePositionSetter.FilePositionResult)11 GGXMLTrailTransactionFinder (com.linkedin.databus2.producers.db.GGXMLTrailTransactionFinder)11 File (java.io.File)11 Logger (org.apache.log4j.Logger)10 Test (org.testng.annotations.Test)9 HashSet (java.util.HashSet)1