zircon/system/ulib/fs/journal/test/journal_test.cc
// Tests that data writes are not ordered at the time "WriteData" is invoked.
Tests that data writes are not ordered at the time "WriteData" is invoked.
Tests that data writes are not ordered at the time " WriteData " is invoked .
TEST_F(JournalTest, DataOperationsAreNotOrderedGlobally) {
  storage::VmoBuffer buffer = registry()->InitializeBuffer(5);
  const std::vector<storage::UnbufferedOperation> operations = {
      {
          zx::unowned_vmo(buffer.vmo().get()),
          {
              storage::OperationType::kWrite,
              .vmo_offset = 0,
              .dev_offset = 20,
              .length = 2,
          },
      },
      {
          zx::unowned_vmo(buffer.vmo().get()),
          {
              storage::OperationType::kWrite,
              .vmo_offset = 1,
              .dev_offset = 200,
              .length = 3,
          },
      },
  };
  JournalRequestVerifier verifier(registry()->info(), registry()->journal(),
                                  registry()->writeback(), 0);
  MockTransactionHandler::TransactionCallback callbacks[] = {
      [&](const std::vector<storage::BufferedOperation>& requests) {
        verifier.SetDataOffset(operations[0].op.length);
        verifier.VerifyDataWrite(operations[1], requests);
        return ZX_OK;
      },
      [&](const std::vector<storage::BufferedOperation>& requests) {
        verifier.SetDataOffset(0);
        verifier.VerifyDataWrite(operations[0], requests);
        return ZX_OK;
      },
  };
  MockTransactionHandler handler(registry(), callbacks, std::size(callbacks));
  {
    Journal journal(&handler, take_info(), take_journal_buffer(), take_data_buffer(), 0,
                    Journal::Options{.sequence_data_writes = false});
    auto first_promise = journal.WriteData({operations[0]});
    auto second_promise = journal.WriteData({operations[1]});
    journal.schedule_task(second_promise.and_then(std::move(first_promise)));
  }
}
TEST_F ( JournalTest , DataOperationsAreNotOrderedGlobally ) { storage :: VmoBuffer buffer = registry ( ) -> InitializeBuffer ( 5 ) ; const std :: vector < storage :: UnbufferedOperation > operations = { { zx :: unowned_vmo ( buffer . vmo ( ) . get ( ) ) , { storage :: OperationType :: kWrite , . vmo_offset = 0 , . dev_offset = 20 , . length = 2 , } , } , { zx :: unowned_vmo ( buffer . vmo ( ) . get ( ) ) , { storage :: OperationType :: kWrite , . vmo_offset = 1 , . dev_offset = 200 , . length = 3 , } , } , } ; JournalRequestVerifier verifier ( registry ( ) -> info ( ) , registry ( ) -> journal ( ) , registry ( ) -> writeback ( ) , 0 ) ; MockTransactionHandler :: TransactionCallback callbacks [ ] = { [ & ] ( const std :: vector < storage :: BufferedOperation > & requests ) { verifier . SetDataOffset ( operations [ 0 ] . op . length ) ; verifier . VerifyDataWrite ( operations [ 1 ] , requests ) ; return ZX_OK ; } , [ & ] ( const std :: vector < storage :: BufferedOperation > & requests ) { verifier . SetDataOffset ( 0 ) ; verifier . VerifyDataWrite ( operations [ 0 ] , requests ) ; return ZX_OK ; } , } ; MockTransactionHandler handler ( registry ( ) , callbacks , std :: size ( callbacks ) ) ; { Journal journal ( & handler , take_info ( ) , take_journal_buffer ( ) , take_data_buffer ( ) , 0 , Journal :: Options { . sequence_data_writes = false } ) ; auto first_promise = journal . WriteData ( { operations [ 0 ] } ) ; auto second_promise = journal . WriteData ( { operations [ 1 ] } ) ; journal . schedule_task ( second_promise . and_then ( std :: move ( first_promise ) ) ) ; } }
Tests that data writes are not ordered at the time "WriteData" is invoked.
Tests that data writes are not ordered at the time " WriteData " is invoked .
// Although we "WriteData" in a particular order, we can "and-then" data // to force an arbitrary order that we want. This is visible in the transaction // callbacks, where we notice "operations[1]" before "operations[0]".