summaryrefslogtreecommitdiffstats
path: root/storage/src/tests/persistence/filestorage/deletebuckettest.cpp
blob: 4c81d96603faecbe7dec774656692ae990c90924 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/log/log.h>
#include <vespa/vdstestlib/cppunit/macros.h>
#include <vespa/storageapi/message/bucket.h>
#include <tests/persistence/common/persistenceproviderwrapper.h>
#include <vespa/persistence/dummyimpl/dummypersistence.h>
#include <tests/persistence/common/filestortestfixture.h>

LOG_SETUP(".deletebuckettest");

namespace storage {

class DeleteBucketTest : public FileStorTestFixture
{
public:
    void testDeleteAbortsOperationsForBucket();

    CPPUNIT_TEST_SUITE(DeleteBucketTest);
    CPPUNIT_TEST(testDeleteAbortsOperationsForBucket);
    CPPUNIT_TEST_SUITE_END();
};

CPPUNIT_TEST_SUITE_REGISTRATION(DeleteBucketTest);

void
DeleteBucketTest::testDeleteAbortsOperationsForBucket()
{
    TestFileStorComponents c(*this, "testDeleteAbortsOperationsForBucket");
    document::BucketId bucket(16, 1);

    createBucket(bucket);
    LOG(info, "TEST STAGE: taking resume guard");
    ResumeGuard rg(c.manager->getFileStorHandler().pause());
    // First put may or may not be queued, since pausing might race with
    // an existing getNextMessage iteration (ugh...).
    c.sendPut(bucket, DocumentIndex(0), PutTimestamp(1000));
    // Put will be queued since thread now must know it's paused.
    c.sendPut(bucket, DocumentIndex(1), PutTimestamp(1000));

    auto deleteMsg = std::make_shared<api::DeleteBucketCommand>(bucket);
    c.top.sendDown(deleteMsg);
    // We should now have two put replies. The first one will either be OK
    // or BUCKET_DELETED depending on whether it raced. The second (which is
    // the one we care about since it's deterministic) must be BUCKET_DELETED.
    // Problem is, their returned ordering is not deterministic so we're left
    // with having to check that _at least_ 1 reply had BUCKET_DELETED. Joy!
    c.top.waitForMessages(2, 60*2);
    std::vector<api::StorageMessage::SP> msgs(c.top.getRepliesOnce());
    CPPUNIT_ASSERT_EQUAL(size_t(2), msgs.size());
    int numDeleted = 0;
    for (uint32_t i = 0; i < 2; ++i) {
        api::StorageReply& reply(dynamic_cast<api::StorageReply&>(*msgs[i]));
        if (reply.getResult().getResult() == api::ReturnCode::BUCKET_DELETED) {
            ++numDeleted;
        }
    }
    CPPUNIT_ASSERT(numDeleted >= 1);
    LOG(info, "TEST STAGE: done, releasing resume guard");
}

} // namespace storage