aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/tests/proton/documentdb/executor_threading_service/executor_threading_service_test.cpp
blob: 322f3c389ad5de076bb5b01da3d4507a556ebdad (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/searchcore/proton/server/executorthreadingservice.h>
#include <vespa/searchcore/proton/server/threading_service_config.h>
#include <vespa/searchcore/proton/test/transport_helper.h>
#include <vespa/vespalib/gtest/gtest.h>
#include <vespa/vespalib/util/sequencedtaskexecutor.h>

using namespace proton;
using vespalib::ISequencedTaskExecutor;
using vespalib::SequencedTaskExecutor;

VESPA_THREAD_STACK_TAG(my_field_writer_executor)

SequencedTaskExecutor*
to_concrete_type(ISequencedTaskExecutor& exec)
{
    return dynamic_cast<SequencedTaskExecutor*>(&exec);
}

class ExecutorThreadingServiceTest : public ::testing::Test {
public:
    TransportAndExecutor _transport;
    std::unique_ptr<ISequencedTaskExecutor> field_writer_executor;
    std::unique_ptr<ExecutorThreadingService> service;
    ExecutorThreadingServiceTest()
        : _transport(1),
          field_writer_executor(SequencedTaskExecutor::create(my_field_writer_executor, 3, 200)),
          service(std::make_unique<ExecutorThreadingService>(_transport.shared(),
                                                             _transport.transport(),
                                                             _transport.clock(),
                                                             *field_writer_executor,
                                                             nullptr,
                                                             ThreadingServiceConfig::make()))
    {
    }
    SequencedTaskExecutor* field_writer() {
        return to_concrete_type(*field_writer_executor);
    }
};

void
assert_executor(SequencedTaskExecutor* exec, uint32_t exp_executors, uint32_t exp_task_limit)
{
    EXPECT_EQ(exp_executors, exec->getNumExecutors());
    EXPECT_EQ(exp_task_limit, exec->first_executor()->getTaskLimit());
}

TEST_F(ExecutorThreadingServiceTest, shared_field_writer_specified_from_the_outside)
{
    EXPECT_EQ(field_writer(), &service->field_writer());
    assert_executor(field_writer(), 3, 200);
}

TEST_F(ExecutorThreadingServiceTest, tasks_limits_can_be_updated)
{
    service->set_task_limits(5, 7, 11);
    EXPECT_EQ(5, service->master_task_limit());
    EXPECT_EQ(7, service->index().getTaskLimit());
    EXPECT_EQ(11, service->summary().getTaskLimit());
    EXPECT_EQ(7, field_writer()->first_executor()->getTaskLimit());
}

GTEST_MAIN_RUN_ALL_TESTS()