summaryrefslogtreecommitdiffstats
path: root/storage/src/tests/distributor/nodeinfotest.cpp
blob: b702ed65f389ae29fca818e4778fe4c15ea6f840 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/vdstestlib/cppunit/macros.h>
#include <iomanip>
#include <iostream>
#include <memory>
#include <vespa/storageapi/message/persistence.h>
#include <vespa/storageframework/defaultimplementation/clock/fakeclock.h>
#include <vespa/storage/distributor/bucketdbupdater.h>
#include <vespa/storageapi/message/bucket.h>
#include <vespa/storageapi/message/state.h>
#include <vespa/document/fieldvalue/document.h>
#include <vespa/vdslib/state/random.h>
#include <vespa/storageapi/message/bucket.h>
#include <vespa/storage/distributor/pendingclusterstate.h>
#include <vespa/vespalib/text/stringtokenizer.h>
#include <vespa/storage/distributor/nodeinfo.h>

#include <iostream>
#include <fstream>
#include <string>

namespace storage {
namespace distributor {

class NodeInfoTest : public CppUnit::TestFixture {
    CPPUNIT_TEST_SUITE(NodeInfoTest);
    CPPUNIT_TEST(testSimple);
    CPPUNIT_TEST_SUITE_END();
public:
    void testSimple();
};

CPPUNIT_TEST_SUITE_REGISTRATION(NodeInfoTest);

void
NodeInfoTest::testSimple()
{
    framework::defaultimplementation::FakeClock clock;
    NodeInfo info(clock);

    CPPUNIT_ASSERT_EQUAL(0, (int)info.getPendingCount(3));
    CPPUNIT_ASSERT_EQUAL(0, (int)info.getPendingCount(9));

    info.incPending(3);
    info.incPending(3);
    info.incPending(3);
    info.incPending(3);
    info.decPending(3);
    info.decPending(4);
    info.incPending(7);
    info.incPending(4);
    info.decPending(3);

    CPPUNIT_ASSERT_EQUAL(2, (int)info.getPendingCount(3));
    CPPUNIT_ASSERT_EQUAL(1, (int)info.getPendingCount(4));
    CPPUNIT_ASSERT_EQUAL(1, (int)info.getPendingCount(7));
    CPPUNIT_ASSERT_EQUAL(0, (int)info.getPendingCount(5));

    info.setBusy(5);
    clock.addSecondsToTime(10);
    info.setBusy(1);
    clock.addSecondsToTime(20);
    info.setBusy(42);

    CPPUNIT_ASSERT_EQUAL(true, info.isBusy(5));
    CPPUNIT_ASSERT_EQUAL(true, info.isBusy(1));
    CPPUNIT_ASSERT_EQUAL(true, info.isBusy(42));
    CPPUNIT_ASSERT_EQUAL(false, info.isBusy(7));

    clock.addSecondsToTime(42);

    CPPUNIT_ASSERT_EQUAL(false, info.isBusy(5));
    CPPUNIT_ASSERT_EQUAL(false, info.isBusy(1));
    CPPUNIT_ASSERT_EQUAL(true, info.isBusy(42));
    CPPUNIT_ASSERT_EQUAL(false, info.isBusy(7));

}

}

}