Search in sources :

Example 6 with Transaction

use of com.linkedin.databus2.producers.ds.Transaction in project databus by linkedin.

the class TestTrailFilePositionSetter method testFailureMode_MalformedLastTransactionInMiddleFile.

/**
   * Verify that corruption that occurs after the desired SCN/transaction doesn't cause errors
   * when requesting an exact SCN.
   */
@Test
public void testFailureMode_MalformedLastTransactionInMiddleFile() throws Exception {
    final Logger log = Logger.getLogger("TestTrailFilePositionSetter.testFailureMode_MalformedLastTransactionInMiddleFile");
    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, 307, /* corrupt last SCN in 2nd file */
    "plugh", false, "");
    TrailFilePositionSetter posSetter = new TrailFilePositionSetter(dir.getAbsolutePath(), TRAIL_FILENAME_PREFIX);
    GGXMLTrailTransactionFinder finder = new GGXMLTrailTransactionFinder();
    FilePositionResult res;
    // corruption at SCN 307 occurs after SCN 299, so latter should be found OK:
    res = posSetter.locateFilePosition(299, finder);
    assertFilePositionResult(res, dir, 299, FilePositionResult.Status.FOUND);
    // SCN 306 is in same transaction as 307, but regexQuery() doesn't fully validate XML => OK
    finder.reset();
    res = posSetter.locateFilePosition(306, finder);
    assertFilePositionResult(res, dir, 306, 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 7 with Transaction

use of com.linkedin.databus2.producers.ds.Transaction in project databus by linkedin.

the class TestTrailFilePositionSetter method testFailureMode_MalformedTransactionForExactScn.

/**
   * Verify that a non-corrupted SCN value within a corrupted transaction causes an exception to be thrown
   * when the exact SCN is requested.
   */
@Test
public void testFailureMode_MalformedTransactionForExactScn() throws Exception {
    final Logger log = Logger.getLogger("TestTrailFilePositionSetter.testFailureMode_MalformedTransactionForExactScn");
    log.info("starting");
    File dir = createTempDir();
    // first SCN is hardcoded always to be 100
    // this adds a non-XML string near the end of the dbupdate for SCN 377, but the SCN value itself is clean:
    createTrailFiles(dir.getAbsolutePath(), TRAIL_FILENAME_PREFIX, 150, /* numTxns, 24 lines each */
    1250, /* numLinesPerFile */
    1, /* numLinesPerNewline */
    "\n", 0, 377, /* corrupt a txn in 3rd file */
    "", true, "kilroy");
    TrailFilePositionSetter posSetter = new TrailFilePositionSetter(dir.getAbsolutePath(), TRAIL_FILENAME_PREFIX);
    GGXMLTrailTransactionFinder finder = new GGXMLTrailTransactionFinder();
    FilePositionResult res;
    // with a full XML parser, this should throw an exception; with regexQuery(), it's fine:
    finder.reset();
    res = posSetter.locateFilePosition(377, finder);
    assertFilePositionResult(res, dir, 377, 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 Transaction

use of com.linkedin.databus2.producers.ds.Transaction in project databus by linkedin.

the class TestTrailFilePositionSetter method testFailureMode_MalformedLastTransactionInLastFile.

/**
   * Verify that corruption in the very last transaction causes USE_LATEST_SCN to return
   * the last SCN from the previous transaction.
   */
@Test
public void testFailureMode_MalformedLastTransactionInLastFile() throws Exception {
    final Logger log = Logger.getLogger("TestTrailFilePositionSetter.testFailureMode_MalformedLastTransactionInLastFile");
    log.info("starting");
    File dir = createTempDir();
    // first SCN is hardcoded always to be 100
    createTrailFiles(dir.getAbsolutePath(), TRAIL_FILENAME_PREFIX, 150, /* numTxns, 24 lines and 2 SCNs each */
    1250, /* numLinesPerFile */
    1, /* numLinesPerNewline */
    "\n", 0, 399, /* corrupt last SCN in 3rd file */
    "quux", false, "");
    TrailFilePositionSetter posSetter = new TrailFilePositionSetter(dir.getAbsolutePath(), TRAIL_FILENAME_PREFIX);
    GGXMLTrailTransactionFinder finder = new GGXMLTrailTransactionFinder();
    FilePositionResult res;
    // corruption at SCN 399 => should get 398 back (same transaction, but again, regexQuery() doesn't fully validate)
    res = posSetter.locateFilePosition(TrailFilePositionSetter.USE_LATEST_SCN, finder);
    assertFilePositionResult(res, dir, 398, 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 9 with Transaction

use of com.linkedin.databus2.producers.ds.Transaction in project databus by linkedin.

the class TestParser method sortMultipleSourcesCheck.

/**
   * Test to see if all the updates within a given transaction are clubbed to together by source, and is sorted by source.
   */
@Test
public void sortMultipleSourcesCheck() throws Exception {
    SortCheckCallback callback = new SortCheckCallback();
    StaxBuilderTest test = new StaxBuilderTest(actualXmlDataDir + "sortMultipleSources.xml", service, callback);
    test.processXml();
}
Also used : StaxBuilderTest(com.linkedin.databus2.ggParser.staxparser.StaxBuilderTest) StaxBuilderTest(com.linkedin.databus2.ggParser.staxparser.StaxBuilderTest) Test(org.testng.annotations.Test)

Example 10 with Transaction

use of com.linkedin.databus2.producers.ds.Transaction 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)

Aggregations

DatabusException (com.linkedin.databus2.core.DatabusException)10 File (java.io.File)9 Test (org.testng.annotations.Test)8 FilePositionResult (com.linkedin.databus.core.TrailFilePositionSetter.FilePositionResult)6 GGXMLTrailTransactionFinder (com.linkedin.databus2.producers.db.GGXMLTrailTransactionFinder)6 Logger (org.apache.log4j.Logger)6 ArrayList (java.util.ArrayList)5 DatabusRuntimeException (com.linkedin.databus.core.DatabusRuntimeException)3 HashSet (java.util.HashSet)3 Schema (org.apache.avro.Schema)3 QueryEvent (com.google.code.or.binlog.impl.event.QueryEvent)2 XidEvent (com.google.code.or.binlog.impl.event.XidEvent)2 DbusEventBufferAppendable (com.linkedin.databus.core.DbusEventBufferAppendable)2 TransactionInfo (com.linkedin.databus.monitoring.mbean.GGParserStatistics.TransactionInfo)2 TransactionState (com.linkedin.databus2.ggParser.XmlStateMachine.TransactionState)2 PhysicalSourceStaticConfig (com.linkedin.databus2.relay.config.PhysicalSourceStaticConfig)2 VersionedSchema (com.linkedin.databus2.schemas.VersionedSchema)2 GenericRecord (org.apache.avro.generic.GenericRecord)2 BinlogEventV4 (com.google.code.or.binlog.BinlogEventV4)1 AbstractBinlogEventV4 (com.google.code.or.binlog.impl.event.AbstractBinlogEventV4)1