Skip to content

Commit

Permalink
Add test with reboots and NextVal
Browse files Browse the repository at this point in the history
  • Loading branch information
shnikd committed Mar 21, 2024
1 parent a239105 commit cfe108c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ class TCopySequence: public TSubOperation {
TSequenceInfo::TPtr srcSequence = context.SS->Sequences.at(srcPath.Base()->PathId);
Y_ABORT_UNLESS(!srcSequence->Sharding.GetSequenceShards().empty());

auto protoSequenceShard = *srcSequence->Sharding.GetSequenceShards().rbegin();
const auto& protoSequenceShard = *srcSequence->Sharding.GetSequenceShards().rbegin();
TShardIdx sequenceShard = FromProto(protoSequenceShard);

const TString acl = Transaction.GetModifyACL().GetDiffACL();
Expand Down
19 changes: 19 additions & 0 deletions ydb/core/tx/schemeshard/ut_helpers/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <ydb/core/tx/data_events/events.h>
#include <ydb/core/tx/data_events/payload_helper.h>
#include <ydb/core/tx/schemeshard/schemeshard.h>
#include <ydb/core/tx/sequenceproxy/sequenceproxy.h>
#include <ydb/core/tx/tx_proxy/proxy.h>
#include <ydb/core/persqueue/events/global.h>
#include <ydb/core/persqueue/ut/common/pq_ut_common.h>
Expand Down Expand Up @@ -2355,4 +2356,22 @@ namespace NSchemeShardUT_Private {

UNIT_ASSERT_C(successIsExpected == (status == NKikimrDataEvents::TEvWriteResult::STATUS_COMPLETED), "Status: " << ev->Get()->Record.GetStatus() << " Issues: " << ev->Get()->Record.GetIssues());
}

void SendNextValRequest(TTestActorRuntime& runtime, const TActorId& sender, const TString& path) {
auto request = MakeHolder<NSequenceProxy::TEvSequenceProxy::TEvNextVal>(path);
runtime.Send(new IEventHandle(NSequenceProxy::MakeSequenceProxyServiceID(), sender, request.Release()));
}

i64 WaitNextValResult(TTestActorRuntime& runtime, const TActorId& sender) {
auto ev = runtime.GrabEdgeEventRethrow<NSequenceProxy::TEvSequenceProxy::TEvNextValResult>(sender);
auto* msg = ev->Get();
UNIT_ASSERT_VALUES_EQUAL(msg->Status, Ydb::StatusIds::SUCCESS);
return msg->Value;
}

i64 DoNextVal(TTestActorRuntime& runtime, const TString& path) {
auto sender = runtime.AllocateEdgeActor(0);
SendNextValRequest(runtime, sender, path);
return WaitNextValResult(runtime, sender);
}
}
4 changes: 4 additions & 0 deletions ydb/core/tx/schemeshard/ut_helpers/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,4 +552,8 @@ namespace NSchemeShardUT_Private {
void UploadRows(TTestActorRuntime& runtime, const TString& tablePath, int partitionIdx, const TVector<ui32>& keyTags, const TVector<ui32>& valueTags, const TVector<ui32>& recordIds);
void WriteRow(TTestActorRuntime& runtime, const ui64 txId, const TString& tablePath, int partitionIdx, const ui32 key, const TString& value, bool successIsExpected = true);

void SendNextValRequest(TTestActorRuntime& runtime, const TActorId& sender, const TString& path);
i64 WaitNextValResult(TTestActorRuntime& runtime, const TActorId& sender);
i64 DoNextVal(TTestActorRuntime& runtime, const TString& path);

} //NSchemeShardUT_Private
10 changes: 9 additions & 1 deletion ydb/core/tx/schemeshard/ut_helpers/test_env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <ydb/core/tablet_flat/tablet_flat_executed.h>
#include <ydb/core/tx/datashard/datashard.h>
#include <ydb/core/tx/schemeshard/schemeshard_private.h>
#include <ydb/core/tx/sequenceproxy/sequenceproxy.h>
#include <ydb/core/tx/tx_allocator/txallocator.h>
#include <ydb/core/tx/tx_proxy/proxy.h>
#include <ydb/core/filestore/core/filestore.h>
Expand Down Expand Up @@ -569,7 +570,7 @@ NSchemeShardUT_Private::TTestEnv::TTestEnv(TTestActorRuntime& runtime, const TTe
set.SetMinimumStepSeconds(5); // 5 seconds
}
//

for (const auto& sid : opts.SystemBackupSIDs_) {
app.AddSystemBackupSID(sid);
}
Expand Down Expand Up @@ -615,6 +616,13 @@ NSchemeShardUT_Private::TTestEnv::TTestEnv(TTestActorRuntime& runtime, const TTe
runtime.RegisterService(MakeTxProxyID(), txProxyId, node);
}

// Create sequence proxies
for (size_t i = 0; i < runtime.GetNodeCount(); ++i) {
IActor* sequenceProxy = NSequenceProxy::CreateSequenceProxy();
TActorId sequenceProxyId = runtime.Register(sequenceProxy, i);
runtime.RegisterService(NSequenceProxy::MakeSequenceProxyServiceID(), sequenceProxyId, i);
}

//SetupBoxAndStoragePool(runtime, sender, TTestTxConfig::DomainUid);

TxReliablePropose = runtime.Register(new TTxReliablePropose(schemeRoot));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ Y_UNIT_TEST_SUITE(TSequenceReboots) {
{NKikimrScheme::StatusAccepted, NKikimrScheme::StatusAlreadyExists, NKikimrScheme::StatusMultipleModifications});
t.TestEnv->TestWaitNotification(runtime, t.TxId);

{
TInactiveZone inactive(activeZone);
i64 value = DoNextVal(runtime, "/MyRoot/Table/myseq");
UNIT_ASSERT_VALUES_EQUAL(value, 1);
}

t.TestEnv->ReliablePropose(runtime, CopyTableRequest(++t.TxId, "/MyRoot", "copy", "/MyRoot/Table"),
{NKikimrScheme::StatusAccepted, NKikimrScheme::StatusAlreadyExists,
NKikimrScheme::StatusMultipleModifications});
Expand All @@ -219,7 +225,8 @@ Y_UNIT_TEST_SUITE(TSequenceReboots) {

{
TInactiveZone inactive(activeZone);
// no inactive finalization
i64 value = DoNextVal(runtime, "/MyRoot/copy/myseq");
UNIT_ASSERT_VALUES_EQUAL(value, 2);
}
});
}
Expand Down

0 comments on commit cfe108c

Please sign in to comment.