// BackupMetadataFile WriteAysnc function with cancellation token canceled test
    // 1. Set up the expected values.
    // 2. WriteAsync call with cancellation token got canceled 
    // 3. Verify it throws and the exception is as expected
    Awaitable<void> BackupMetadataFileTests::Test_BackupMetadataFile_WriteAsync_WithCanceledToken_Throws(
        __in KString const & fileName)
    {
        NTSTATUS status = STATUS_UNSUCCESSFUL;

        KAllocator & allocator = underlyingSystem_->PagedAllocator();
        KWString filePath(allocator, fileName);

        BackupMetadataFile::SPtr backupMetadataFileSPtr = nullptr;
        status = BackupMetadataFile::Create(
            *prId_,
            filePath,
            allocator,
            backupMetadataFileSPtr);
        VERIFY_IS_TRUE(NT_SUCCESS(status));

        // Expected 
        const FABRIC_BACKUP_OPTION expectedBackupOption = FABRIC_BACKUP_OPTION_FULL;
        KGuid expectedParentBackupId;
        expectedParentBackupId.CreateNew();
        KGuid expectedBackupId;
        expectedBackupId.CreateNew();
        KGuid expectedPartitionId;
        expectedPartitionId.CreateNew();
        const FABRIC_REPLICA_ID expectedReplicaId = 16;
        const LONG64 expectedDataLossNumber = 32;
        const LONG64 expectedConfigurationNumber = 64;
        TxnReplicator::Epoch expectedStartingEpoch = TxnReplicator::Epoch(expectedDataLossNumber, expectedConfigurationNumber);
        FABRIC_SEQUENCE_NUMBER expectedStartingLSN = 8;
        TxnReplicator::Epoch expectedBackupEpoch = TxnReplicator::Epoch(expectedDataLossNumber, expectedConfigurationNumber);
        FABRIC_SEQUENCE_NUMBER expectedBackupLSN = 128;

        CancellationTokenSource::SPtr cts;
        status = CancellationTokenSource::Create(allocator, BACKUPMETADATAFILETEST_TAG, cts);
        VERIFY_IS_TRUE(NT_SUCCESS(status));
        cts->Cancel();

        status = co_await backupMetadataFileSPtr->WriteAsync(
            expectedBackupOption,
            expectedParentBackupId,
            expectedBackupId,
            expectedPartitionId,
            expectedReplicaId,
            expectedStartingEpoch,
            expectedStartingLSN,
            expectedBackupEpoch,
            expectedBackupLSN,
            cts->Token);
        VERIFY_ARE_EQUAL(STATUS_CANCELLED, status);

        Common::File::Delete(static_cast<LPCWSTR>(fileName), true);
    }
    void ReplicaManagerWrapper::UpdateConfiguration(
        wstring const & previousReplicasDescription,
        ULONG previousQuorum,
        wstring const & currentReplicasDescription,
        ULONG currentQuorum)
    {
        ReplicaInformationVector previousActiveReplicas;
        size_t previousReplicaCount;
        GenerateActiveReplicas(previousReplicasDescription, previousReplicaCount, previousActiveReplicas);

        ReplicaInformationVector currentActiveReplicas;
        size_t currentReplicaCount;
        GenerateActiveReplicas(currentReplicasDescription, currentReplicaCount, currentActiveReplicas);
        
        Trace.WriteInfo(TestReplicaManagerSource,
            "*********** UpdateConfiguration with current replicas: {0}, quorum {1}, previous: {2}, quorum {3}", 
            currentReplicasDescription,
            currentQuorum,
            previousReplicasDescription,
            previousQuorum);

        auto error = replicaManagerSPtr_->UpdateConfiguration(
            previousActiveReplicas,
            previousQuorum,
            currentActiveReplicas, 
            currentQuorum, 
            true,
            true);
        VERIFY_IS_TRUE(error.IsSuccess(), L"UpdateConfiguration (catchup replicas set) should succeed");
    }
Exemplo n.º 3
0
TEST_FIXTURE(e2e_raw_client, update_entity_with_patch)
{
	auto model = client.get_model().get();

	//check the old value
	auto query_result = client.get_data_from_server(U("Accounts(101)")).get();
	auto old_entity = std::dynamic_pointer_cast<odata_entity_value>(query_result[0]);
	std::shared_ptr<odata_value> old_value;
	old_entity->get_property_value(U("Country"), old_value);
	auto old_country = std::dynamic_pointer_cast<odata_primitive_value>(old_value);
	VERIFY_ARE_EQUAL(U("US"), old_country->as<::utility::string_t>());

	//update the entity with patch
	old_entity->set_value(U("Country"), U("GB"));

	auto response_code = client.patch_entity(U("Accounts"), old_entity).get();
	VERIFY_ARE_EQUAL(204, response_code);

	//query the updated entity
	auto check_query = client.get_data_from_server(U("Accounts(101)")).get();

	auto new_entity = std::dynamic_pointer_cast<odata_entity_value>(check_query[0]);
	std::shared_ptr<odata_value> property_value;
	VERIFY_IS_TRUE(new_entity->get_property_value(U("Country"), property_value));
	auto primitive_value = std::dynamic_pointer_cast<odata_primitive_value>(property_value);
	::utility::string_t new_country = primitive_value->as<::utility::string_t>();
	VERIFY_ARE_EQUAL(U("GB"), new_country);
}
Exemplo n.º 4
0
TEST_FIXTURE(e2e_raw_client, create_entity)
{
	auto model = client.get_model().get();

	::utility::string_t entity_set_name = U("Accounts");
	std::shared_ptr<odata_entity_value> entity = std::make_shared<odata_entity_value>(model->find_entity_set_type(entity_set_name));

	entity->set_value(U("AccountID"), 130);
	entity->set_value(U("Country"), U("CN"));

	auto accountinfo_type = model->find_complex_type(U("AccountInfo"));
	auto account_info = std::make_shared<odata_complex_value>(accountinfo_type);
	::utility::string_t account_firstname = U("cpp");
	::utility::string_t account_lastname = U("client");
	account_info->set_value(U("FirstName"), account_firstname);
	account_info->set_value(U("LastName"), account_lastname);

	entity->set_value(U("AccountInfo"), account_info);

	auto response_code = client.create_entity(entity_set_name, entity).get();
	VERIFY_ARE_EQUAL(201, response_code);

	//query the newly created entity
	auto query_result = client.get_data_from_server(U("Accounts(130)")).get();
	VERIFY_ARE_EQUAL(query_result.size(), 1);

	auto new_entity = std::dynamic_pointer_cast<odata_entity_value>(query_result[0]);
	std::shared_ptr<odata_value> property_value;
	VERIFY_IS_TRUE(entity->get_property_value(U("AccountID"), property_value));
	auto primitive_value = std::dynamic_pointer_cast<odata_primitive_value>(property_value);
	int32_t new_id = primitive_value->as<int32_t>();
	VERIFY_ARE_EQUAL(130, new_id);
}
    template <bool ManualReset> void AsyncWaitHandleDestructRaceCallback()
    {
        auto wh = make_shared<AsyncWaitHandle<ManualReset>>();

        AutoResetEvent callbackCanStart(false);
        AutoResetEvent resultEvent(false);
        wh->BeginWaitOne(
            TimeSpan::MaxValue,
            [&resultEvent, &callbackCanStart] (AsyncOperationSPtr const & op) mutable
            {
                Trace.WriteInfo(TraceType, "callback waiting for action");
                callbackCanStart.WaitOne(); 
                Trace.WriteInfo(TraceType, "callback starting action");
                ErrorCode result = op->End(op);
                VERIFY_IS_TRUE(result.IsSuccess());
                resultEvent.Set();
                Trace.WriteInfo(TraceType, "leaving callback");
            },
            AsyncOperationSPtr());

        //make wh destruction and callback race
        wh->Set();
        wh.reset();
        callbackCanStart.Set();

        BOOST_REQUIRE(resultEvent.WaitOne(TimeSpan::FromSeconds(60)));
    }
Exemplo n.º 6
0
void FontTests::TestSetFontAdjustsWindow()
{
    if (!OneCoreDelay::IsIsWindowPresent())
    {
        Log::Comment(L"Adjusting window size by changing font scenario can't be checked on platform without classic window operations.");
        Log::Result(WEX::Logging::TestResults::Skipped);
        return;
    }

    const HANDLE hConsoleOutput = GetStdOutputHandle();
    const HWND hwnd = GetConsoleWindow();
    VERIFY_IS_TRUE(!!IsWindow(hwnd));
    RECT rc = { 0 };

    CONSOLE_FONT_INFOEX cfiex = { 0 };
    cfiex.cbSize = sizeof(cfiex);

    Log::Comment(L"First set the console window to Consolas 16.");
    wcscpy_s(cfiex.FaceName, L"Consolas");
    cfiex.dwFontSize.Y = 16;

    VERIFY_WIN32_BOOL_SUCCEEDED(OneCoreDelay::SetCurrentConsoleFontEx(hConsoleOutput, FALSE, &cfiex));
    Sleep(250);
    VERIFY_WIN32_BOOL_SUCCEEDED(GetClientRect(hwnd, &rc), L"Retrieve client rectangle size for Consolas 16.");
    SIZE szConsolas;
    szConsolas.cx = rc.right - rc.left;
    szConsolas.cy = rc.bottom - rc.top;
    Log::Comment(NoThrowString().Format(L"Client rect size is (X: %d, Y: %d)", szConsolas.cx, szConsolas.cy));

    Log::Comment(L"Adjust console window to Lucida Console 12.");
    wcscpy_s(cfiex.FaceName, L"Lucida Console");
    cfiex.dwFontSize.Y = 12;

    VERIFY_WIN32_BOOL_SUCCEEDED(OneCoreDelay::SetCurrentConsoleFontEx(hConsoleOutput, FALSE, &cfiex));
    Sleep(250);
    VERIFY_WIN32_BOOL_SUCCEEDED(GetClientRect(hwnd, &rc), L"Retrieve client rectangle size for Lucida Console 12.");
    SIZE szLucida;
    szLucida.cx = rc.right - rc.left;
    szLucida.cy = rc.bottom - rc.top;

    Log::Comment(NoThrowString().Format(L"Client rect size is (X: %d, Y: %d)", szLucida.cx, szLucida.cy));
    Log::Comment(L"Window should shrink in size when going to Lucida 12 from Consolas 16.");
    VERIFY_IS_LESS_THAN(szLucida.cx, szConsolas.cx);
    VERIFY_IS_LESS_THAN(szLucida.cy, szConsolas.cy);

    Log::Comment(L"Adjust console window back to Consolas 16.");
    wcscpy_s(cfiex.FaceName, L"Consolas");
    cfiex.dwFontSize.Y = 16;

    VERIFY_WIN32_BOOL_SUCCEEDED(OneCoreDelay::SetCurrentConsoleFontEx(hConsoleOutput, FALSE, &cfiex));
    Sleep(250);
    VERIFY_WIN32_BOOL_SUCCEEDED(GetClientRect(hwnd, &rc), L"Retrieve client rectangle size for Consolas 16.");
    szConsolas.cx = rc.right - rc.left;
    szConsolas.cy = rc.bottom - rc.top;

    Log::Comment(NoThrowString().Format(L"Client rect size is (X: %d, Y: %d)", szConsolas.cx, szConsolas.cy));
    Log::Comment(L"Window should grow in size when going from Lucida 12 to Consolas 16.");
    VERIFY_IS_LESS_THAN(szLucida.cx, szConsolas.cx);
    VERIFY_IS_LESS_THAN(szLucida.cy, szConsolas.cy);
}
Exemplo n.º 7
0
    void NodeIdRangeTests::TestSubtractRanges(NodeIdRange const & range, vector<NodeIdRange> const & excludes)
    {
        vector<NodeIdRange> result;

        range.Subtract(excludes, result);
        Trace.WriteInfo(TraceRangeTest, "Range {0} exclude {1} returned {2}",
            range, excludes, result);

        LargeInteger overlapSize = LargeInteger::Zero;
        for (size_t i = 0; i < result.size(); i++)
        {
            VERIFY_IS_TRUE(!result[i].IsEmpty);
            VERIFY_IS_TRUE(range.Contains(result[i]));

            for (size_t j = 0; j < excludes.size(); j++)
            {
                VERIFY_IS_TRUE(result[i].Disjoint(excludes[j]));
            }

            overlapSize = overlapSize + GetOverlapSize(range, result[i]);
        }

        for (size_t i = 0; i + 1 < result.size(); i++)
        {
            for (size_t j = i + 1; j < result.size(); j++)
            {
                VERIFY_IS_TRUE(result[i].Disjoint(result[j]));
            }
        }

        for (size_t i = 0; i < excludes.size(); i++)
        {
            overlapSize = overlapSize + GetOverlapSize(range, excludes[i]);
        }

        VERIFY_IS_TRUE(GetRangeSize(range) == overlapSize);
    }
 void ReplicaManagerWrapper::UpdateConfiguration(
     ReplicaInformationVector const & previousActiveReplicas,
     ULONG previousQuorum,
     ReplicaInformationVector const & currentActiveReplicas,
     ULONG currentQuorum)
 {
     auto error = replicaManagerSPtr_->UpdateConfiguration(
         previousActiveReplicas,
         previousQuorum,
         currentActiveReplicas, 
         currentQuorum, 
         true,
         true);
     VERIFY_IS_TRUE(error.IsSuccess(), L"UpdateConfiguration (catchup replicas set) should succeed");
 }
Exemplo n.º 9
0
    void NodeIdRangeTests::TestSubtract(NodeIdRange const & range, NodeIdRange const & exclude)
    {
        NodeIdRange range1, range2;
        range.Subtract(exclude, range1, range2);

        Trace.WriteInfo(TraceRangeTest, "Range {0} exclude {1} returned {2} and {3}",
            range, exclude, range1, range2);

        if (!range1.IsEmpty)
        {
            VERIFY_IS_TRUE(range.Contains(range1) && exclude.Disjoint(range1));
            if (!range2.IsEmpty)
            {
                VERIFY_IS_TRUE(range1.Disjoint(range2) && !range1.IsSuccAdjacent(range2) && !range1.IsPredAdjacent(range2));
            }
        }

        if (!range2.IsEmpty)
        {
            VERIFY_IS_TRUE((range2.IsEmpty || range.Contains(range2)) && exclude.Disjoint(range2));
        }

        VERIFY_IS_TRUE(GetRangeSize(range) == GetOverlapSize(range, exclude) + GetRangeSize(range1) + GetRangeSize(range2));
    }
    template <bool ManualReset> void AsyncWaitHandleSetBeforeWait()
    {
        AsyncWaitHandle<ManualReset> asyncWaitHandle(true);

        AutoResetEvent resultEvent(false);
        asyncWaitHandle.BeginWaitOne(
            TimeSpan::MaxValue,
            [&asyncWaitHandle, &resultEvent] (AsyncOperationSPtr const & op)
            {
                ErrorCode result = asyncWaitHandle.EndWaitOne(op);
                VERIFY_IS_TRUE(result.IsSuccess());
                resultEvent.Set();
            },
            AsyncOperationSPtr());

        BOOST_REQUIRE(resultEvent.WaitOne(TimeSpan::FromSeconds(60)));
    }
Exemplo n.º 11
0
TEST_FIXTURE(e2e_raw_client, query_basic_properties_in_entity)
{
	auto query_result = client.get_data_from_server(U("People(4)")).get();
	VERIFY_ARE_EQUAL(query_result.size(), 1);
	VERIFY_ARE_EQUAL(edm_type_kind_t::Entity, query_result[0]->get_value_type()->get_type_kind());

	std::shared_ptr<odata_entity_value> entity = std::dynamic_pointer_cast<odata_entity_value>(query_result[0]);

	//collection property
	std::shared_ptr<odata_value> collection_property;
	VERIFY_IS_TRUE(entity->get_property_value(U("Numbers"), collection_property));
	VERIFY_ARE_EQUAL(edm_type_kind_t::Collection, collection_property->get_value_type()->get_type_kind());

	auto collection_value = std::dynamic_pointer_cast<odata_collection_value>(collection_property);
	auto collection_vector = collection_value->get_collection_values();
	VERIFY_ARE_EQUAL(3, collection_vector.size());

	auto collectin_member = std::dynamic_pointer_cast<odata_primitive_value>(collection_vector[1]);
	VERIFY_ARE_EQUAL(U("555-555-5555"), collectin_member->as<::utility::string_t>());

	//TODO-tiano: check the other property types 
}
Exemplo n.º 12
0
 void CreateAndOpenReplicaManager()
 {
     perfCounters_ = REPerformanceCounters::CreateInstance(PartitionId,1);
     IReplicatorHealthClientSPtr temp;
     ApiMonitoringWrapperSPtr temp2;
     config_ = REInternalSettings::Create(nullptr,oldConfig_),
     replicaManagerSPtr_ = std::shared_ptr<ReplicaManager>(new ReplicaManager(
         config_,
         false,
         perfCounters_,
         1, /* ReplicaId*/
         false, /* requireserviceACK */
         endpointUniqueId_, 
         transport_,
         0, /* initialProgress */
         ReplicaManagerEpoch, 
         stateProvider_,
         partition_,
         temp,
         temp2,
         PartitionId));
     VERIFY_IS_TRUE(replicaManagerSPtr_->Open().IsSuccess(), L"Replica manager opened");
 }
Exemplo n.º 13
0
        Awaitable<void> ReplicatorPerfTest::Run(
            __in wstring const & testFolder,
            __in int concurrentTransactions,
            __in int totalTransactions,
            __in Data::Log::LogManager & logManager)
        {
#ifndef PERF_TEST
            UNREFERENCED_PARAMETER(testFolder);
            UNREFERENCED_PARAMETER(concurrentTransactions);
            UNREFERENCED_PARAMETER(totalTransactions);
            UNREFERENCED_PARAMETER(logManager);
#else
            Replica::SPtr replica = Replica::Create(
                pId_,
                rId_,
                testFolder,
                logManager,
                underlyingSystem_->PagedAllocator());

            co_await replica->OpenAsync();

            FABRIC_EPOCH epoch1; epoch1.DataLossNumber = 1; epoch1.ConfigurationNumber = 1; epoch1.Reserved = nullptr;
            co_await replica->ChangeRoleAsync(epoch1, FABRIC_REPLICA_ROLE_PRIMARY);

            replica->SetReadStatus(FABRIC_SERVICE_PARTITION_ACCESS_STATUS_GRANTED);
            replica->SetWriteStatus(FABRIC_SERVICE_PARTITION_ACCESS_STATUS_GRANTED);

            KUri::CSPtr stateProviderName = GetStateProviderName(0);
            {
                Transaction::SPtr txn;
                replica->TxnReplicator->CreateTransaction(txn);
                KFinally([&] {txn->Dispose(); });

                NTSTATUS status = co_await replica->TxnReplicator->AddAsync(*txn, *stateProviderName, L"ReplicatorPerfTest");
                VERIFY_IS_TRUE(NT_SUCCESS(status));
                co_await txn->CommitAsync();
            }

            {
                IStateProvider2::SPtr stateProvider2;
                NTSTATUS status = replica->TxnReplicator->Get(*stateProviderName, stateProvider2);
                VERIFY_IS_TRUE(NT_SUCCESS(status));
                VERIFY_IS_NOT_NULL(stateProvider2);
                VERIFY_ARE_EQUAL(*stateProviderName, stateProvider2->GetName());

                IStore<int, int>::SPtr store = dynamic_cast<IStore<int, int>*>(stateProvider2.RawPtr());

                Stopwatch s;
                s.Start();

                KArray<Awaitable<void>> tasks(underlyingSystem_->PagedAllocator(), concurrentTransactions, 0);

                for (int i = 0; i < concurrentTransactions; i++)
                {
                    status = tasks.Append(DoWorkOnKey(store, replica, totalTransactions / concurrentTransactions, i));
                    KInvariant(NT_SUCCESS(status));
                }

                co_await TaskUtilities<Awaitable<void>>::WhenAll(tasks);

                s.Stop();

                int64 txPerSec = ((totalTransactions * 1000) / s.ElapsedMilliseconds);

                Trace.WriteInfo(
                    TraceComponent,
                    "{0}: Tx/Sec is {1}",
                    prId_->TraceId,
                    txPerSec);
            }

            replica->SetReadStatus(FABRIC_SERVICE_PARTITION_ACCESS_STATUS_NOT_PRIMARY);
            replica->SetWriteStatus(FABRIC_SERVICE_PARTITION_ACCESS_STATUS_NOT_PRIMARY);

            co_await replica->CloseAsync();
#endif
            co_return;
        }
Exemplo n.º 14
0
VOID
FailCoalesceFlushTest(
    KGuid diskId,
    KtlLogManager::SPtr logManager
    )
{
    NTSTATUS status;
    KGuid logContainerGuid;
    KtlLogContainerId logContainerId;
    StreamCloseSynchronizer closeStreamSync;
    ContainerCloseSynchronizer closeContainerSync;

    logContainerGuid.CreateNew();
    logContainerId = static_cast<KtlLogContainerId>(logContainerGuid);
    
    //
    // Create container and a stream within it
    //
    {
        KtlLogManager::AsyncCreateLogContainer::SPtr createContainerAsync;
        LONGLONG logSize = DefaultTestLogFileSize;
        KtlLogContainer::SPtr logContainer;
        KSynchronizer sync;
        KGuid logStreamGuid;
        KtlLogStreamId logStreamId;

        logStreamGuid.CreateNew();
        logStreamId = static_cast<KtlLogStreamId>(logStreamGuid);
        
        status = logManager->CreateAsyncCreateLogContainerContext(createContainerAsync);
        VERIFY_IS_TRUE(NT_SUCCESS(status));
        createContainerAsync->StartCreateLogContainer(diskId,
                                             logContainerId,
                                             logSize,
                                             0,            // Max Number Streams
                                             0,            // Max Record Size
                                             logContainer,
                                             NULL,         // ParentAsync
                                             sync);
        status = sync.WaitForCompletion();
        VERIFY_IS_TRUE(NT_SUCCESS(status));

        {
            KtlLogContainer::AsyncCreateLogStreamContext::SPtr createStreamAsync;
            KtlLogStream::SPtr logStream;
            ULONG metadataLength = 0x10000;
            
            status = logContainer->CreateAsyncCreateLogStreamContext(createStreamAsync);
            VERIFY_IS_TRUE(NT_SUCCESS(status));
            
            KBuffer::SPtr securityDescriptor = nullptr;
            KtlLogStreamType logStreamType = KLogicalLogInformation::GetLogicalLogStreamType();

            createStreamAsync->StartCreateLogStream(logStreamId,
                                                    logStreamType,
                                                    nullptr,           // Alias
                                                    nullptr,
                                                    securityDescriptor,
                                                    metadataLength,
                                                    DEFAULT_STREAM_SIZE,
                                                    DEFAULT_MAX_RECORD_SIZE,
                                                    logStream,
                                                    NULL,    // ParentAsync
                                                    sync);

            
            status = sync.WaitForCompletion();
            VERIFY_IS_TRUE(NT_SUCCESS(status));
          
            //
            // Verify that log stream id is set correctly
            //
            KtlLogStreamId queriedLogStreamId;
            logStream->QueryLogStreamId(queriedLogStreamId);

            VERIFY_IS_TRUE(queriedLogStreamId.Get() == logStreamId.Get() ? true : false);

            logStream->StartClose(NULL,
                             closeStreamSync.CloseCompletionCallback());

            status = closeStreamSync.WaitForCompletion();
            VERIFY_IS_TRUE(NT_SUCCESS(status));
			logStream = nullptr;
        }

        //
        // Open the stream
        //
        {
            KtlLogContainer::AsyncOpenLogStreamContext::SPtr openStreamAsync;
            KtlLogStream::SPtr logStream;
            ULONG metadataLength;
            
            status = logContainer->CreateAsyncOpenLogStreamContext(openStreamAsync);
            VERIFY_IS_TRUE(NT_SUCCESS(status));
            openStreamAsync->StartOpenLogStream(logStreamId,
                                                    &metadataLength,
                                                    logStream,
                                                    NULL,    // ParentAsync
                                                    sync);
            
            status = sync.WaitForCompletion();
            VERIFY_IS_TRUE(NT_SUCCESS(status));


            //
            // Create an interceptor for the closing flush for the
            // coalesce records and then apply it. Once applied close
            // the stream and verify it doesn't stop responding.
            //
            status = CompleteOnStartInterceptor<OverlayStream::CoalesceRecords::AsyncAppendOrFlushContext>::Create(KTL_TAG_TEST,
                                                        *g_Allocator,
                                                        STATUS_INSUFFICIENT_RESOURCES,
                                                        FailCoalesceFlushInterceptor);
            VERIFY_IS_TRUE(NT_SUCCESS(status));


            KtlLogStreamUser* logStreamUser = static_cast<KtlLogStreamUser*>(logStream.RawPtr());
            KtlLogStreamKernel* logStreamKernel = static_cast<KtlLogStreamKernel*>(logStreamUser->GetKernelPointer());
            OverlayStream* overlayStream = logStreamKernel->GetOverlayStream();
            OverlayStream::CoalesceRecords* coalesceRecords = (overlayStream->GetCoalesceRecords()).RawPtr();
            OverlayStream::CoalesceRecords::AsyncAppendOrFlushContext* closeFlushContext = coalesceRecords->GetCloseFlushContext();

            FailCoalesceFlushInterceptor->EnableIntercept(*closeFlushContext);
            
            
            logStream->StartClose(NULL,
                             closeStreamSync.CloseCompletionCallback());

            // Allow time for the stream to close and the coalesce
            // flush async to finish up.
            KNt::Sleep(1000);
            
            FailCoalesceFlushInterceptor->DisableIntercept();
            FailCoalesceFlushInterceptor = nullptr;
            
            status = closeStreamSync.WaitForCompletion(60 * 1000);
            VERIFY_IS_TRUE(NT_SUCCESS(status));
			logStream = nullptr;
        }
        
        //
        // Delete the stream
        //
        {
            KtlLogContainer::AsyncDeleteLogStreamContext::SPtr deleteStreamAsync;
            
            status = logContainer->CreateAsyncDeleteLogStreamContext(deleteStreamAsync);
            VERIFY_IS_TRUE(NT_SUCCESS(status));
            deleteStreamAsync->StartDeleteLogStream(logStreamId,
                                                    NULL,    // ParentAsync
                                                    sync);
            
            status = sync.WaitForCompletion();
            VERIFY_IS_TRUE(NT_SUCCESS(status));            
        }

        logContainer->StartClose(NULL,
                         closeContainerSync.CloseCompletionCallback());

        status = closeContainerSync.WaitForCompletion();
        VERIFY_IS_TRUE(NT_SUCCESS(status));

        KtlLogManager::AsyncDeleteLogContainer::SPtr deleteContainerAsync;
        
        status = logManager->CreateAsyncDeleteLogContainerContext(deleteContainerAsync);
        VERIFY_IS_TRUE(NT_SUCCESS(status));
        deleteContainerAsync->StartDeleteLogContainer(diskId,
                                             logContainerId,
                                             NULL,         // ParentAsync
                                             sync);
        status = sync.WaitForCompletion();
        VERIFY_IS_TRUE(NT_SUCCESS(status));     
    }
}
Exemplo n.º 15
0
 void CloseReplicaManager()
 {
     VERIFY_IS_TRUE(replicaManagerSPtr_->Close(false).IsSuccess(), L"Replica manager closed");
 }
Exemplo n.º 16
0
    void LruCacheTest::PerfTestHelper(
        int operationCount,
        size_t capacity,
        bool enableTrim)
    {
        //SetVerifyOutput localVerifySettings(VerifyOutputSettings::LogOnlyFailures);

        size_t bucketCount = 10240;

        LruCache<wstring, TestCacheEntry> cache(enableTrim ? capacity : 0, bucketCount);

        Random rand(static_cast<int>(DateTime::Now().Ticks));
        vector<TestCacheEntrySPtr> entries;
        for (auto ix=0; ix<operationCount; ++ix)
        {
            entries.push_back(make_shared<TestCacheEntry>(GetRandomKey(rand)));
        }

        Stopwatch stopwatch;

        // Write
        
        stopwatch.Restart();
        for (auto it=entries.begin(); it!=entries.end(); ++it)
        {
            auto entry = *it;
            bool success = cache.TryPutOrGet(entry);
            VERIFY_IS_TRUE(success);
        }
        stopwatch.Stop();

        Trace.WriteInfo(
            TraceComponent, 
            "LruCache-put: operations={0} elapsed={1} throughput={2} ops/s", 
            cache.Size, 
            stopwatch.Elapsed,
            (double)cache.Size / stopwatch.ElapsedMilliseconds * 1000);

        // Read

        stopwatch.Restart();
        for (auto it=entries.begin(); it!=entries.end(); ++it)
        {
            shared_ptr<TestCacheEntry> result;
            bool success = cache.TryGet((*it)->GetKey(), result);
            VERIFY_IS_TRUE(success);
        }
        stopwatch.Stop();

        Trace.WriteInfo(
            TraceComponent, 
            "LruCache-get: operations={0} elapsed={1} throughput={2} ops/s", 
            cache.Size, 
            stopwatch.Elapsed,
            (double)cache.Size / stopwatch.ElapsedMilliseconds * 1000);

        Trace.WriteInfo(
            TraceComponent, 
            "CacheSize: {0}",
            cache.Size);
    }
    // BackupMetadataFile Equal function test
    // 1. Set up the expected values.
    // 2. Equal call on same BackupMetadataFile should return true.
    // 3. Equal call on different BackupMetadataFile should return false.
    Awaitable<void> BackupMetadataFileTests::Test_BackupMetadataFile_Equal(
        __in KString const & fileName)
    {
        NTSTATUS status = STATUS_UNSUCCESSFUL;

        KAllocator & allocator = underlyingSystem_->PagedAllocator();
        KWString filePath(allocator, fileName);

        BackupMetadataFile::SPtr backupMetadataFileSPtr = nullptr;
        status = BackupMetadataFile::Create(
            *prId_,
            filePath,
            allocator,
            backupMetadataFileSPtr);
        VERIFY_IS_TRUE(NT_SUCCESS(status));

        // Expected 
        const FABRIC_BACKUP_OPTION expectedBackupOption = FABRIC_BACKUP_OPTION_FULL;
        KGuid expectedParentBackupId;
        expectedParentBackupId.CreateNew();
        KGuid expectedBackupId;
        expectedBackupId.CreateNew();
        KGuid expectedPartitionId;
        expectedPartitionId.CreateNew();
        const FABRIC_REPLICA_ID expectedReplicaId = 16;
        const LONG64 expectedDataLossNumber = 32;
        const LONG64 expectedConfigurationNumber = 64;
        TxnReplicator::Epoch expectedStartingEpoch = TxnReplicator::Epoch(expectedDataLossNumber, expectedConfigurationNumber);
        FABRIC_SEQUENCE_NUMBER expectedStartingLSN = 8;
        TxnReplicator::Epoch expectedBackupEpoch = TxnReplicator::Epoch(expectedDataLossNumber, expectedConfigurationNumber);
        FABRIC_SEQUENCE_NUMBER expectedBackupLSN = 128;

        status = co_await backupMetadataFileSPtr->WriteAsync(
            expectedBackupOption,
            expectedParentBackupId,
            expectedBackupId,
            expectedPartitionId,
            expectedReplicaId,
            expectedStartingEpoch,
            expectedStartingLSN,
            expectedBackupEpoch,
            expectedBackupLSN,
            CancellationToken::None);
        VERIFY_IS_TRUE(NT_SUCCESS(status));

        KGuid readId;
        readId.CreateNew();
        status = co_await backupMetadataFileSPtr->ReadAsync(readId, CancellationToken::None);
        VERIFY_IS_TRUE(NT_SUCCESS(status));

        // Same BackupMetadataFile should equal
        CODING_ERROR_ASSERT(backupMetadataFileSPtr->Equals(*backupMetadataFileSPtr));

        BackupMetadataFile::SPtr newBackupMetadataFileSPtr = nullptr;
        status = BackupMetadataFile::Create(
            *prId_,
            filePath,
            allocator,
            newBackupMetadataFileSPtr);
        VERIFY_IS_TRUE(NT_SUCCESS(status));

        // The new BackupMetadataFile backup option set to incremental.
        status = co_await newBackupMetadataFileSPtr->WriteAsync(
            FABRIC_BACKUP_OPTION_INCREMENTAL,
            expectedParentBackupId,
            expectedBackupId,
            expectedPartitionId,
            expectedReplicaId,
            expectedStartingEpoch,
            expectedStartingLSN,
            expectedBackupEpoch,
            expectedBackupLSN,
            CancellationToken::None);
        VERIFY_IS_TRUE(NT_SUCCESS(status));

        status = co_await newBackupMetadataFileSPtr->ReadAsync(readId, CancellationToken::None);
        VERIFY_IS_TRUE(NT_SUCCESS(status));

        // Different BackupMetadataFiles should return false
        CODING_ERROR_ASSERT(backupMetadataFileSPtr->Equals(*newBackupMetadataFileSPtr) == false);

        Common::File::Delete(static_cast<LPCWSTR>(fileName), true);
    }