1import time
2from couchbase_helper.documentgenerator import BlobGenerator
3from eviction.evictionbase import EvictionBase
4from membase.helper.cluster_helper import ClusterOperationHelper
5from remote.remote_util import RemoteMachineShellConnection
6
7class EvictionChangePolicy(EvictionBase):
8
9    def test_reproducer_MB_11698(self):
10        gen_create = BlobGenerator('eviction', 'eviction-', self.value_size, end=self.num_items)
11        gen_create2 = BlobGenerator('eviction2', 'eviction2-', self.value_size, end=self.num_items)
12        self._load_all_buckets(self.master, gen_create, "create", 0)
13        self._wait_for_stats_all_buckets(self.servers[:self.nodes_init])
14        self._verify_stats_all_buckets(self.servers[:self.nodes_init])
15        remote = RemoteMachineShellConnection(self.master)
16        for bucket in self.buckets:
17            output, _ = remote.execute_couchbase_cli(cli_command='bucket-edit',
18                                                         cluster_host="localhost",
19                                                         user=self.master.rest_username,
20                                                         password=self.master.rest_password,
21                                                         options='--bucket=%s --bucket-eviction-policy=valueOnly' % bucket.name)
22            self.assertTrue(' '.join(output).find('SUCCESS') != -1, 'Eviction policy wasn\'t changed')
23        ClusterOperationHelper.wait_for_ns_servers_or_assert(
24                                            self.servers[:self.nodes_init], self,
25                                            wait_time=self.wait_timeout, wait_if_warmup=True)
26        self.sleep(10, 'Wait some time before next load')
27        self._load_all_buckets(self.master, gen_create2, "create", 0)
28        self._wait_for_stats_all_buckets(self.servers[:self.nodes_init], timeout=self.wait_timeout * 5)
29        self._verify_stats_all_buckets(self.servers[:self.nodes_init])
30
31    def test_warm_up_with_eviction(self):
32        gen_create = BlobGenerator('eviction', 'eviction-', self.value_size, end=self.num_items)
33        gen_create2 = BlobGenerator('eviction2', 'eviction2-', self.value_size, end=self.num_items)
34        self._load_all_buckets(self.master, gen_create, "create", 0)
35        self._wait_for_stats_all_buckets(self.servers[:self.nodes_init])
36        self._verify_stats_all_buckets(self.servers[:self.nodes_init])
37        self.timeout = self.wait_timeout
38        self.without_access_log = False
39        self._stats_befor_warmup(self.buckets[0])
40        self._restart_memcache(self.buckets[0])
41        ClusterOperationHelper.wait_for_ns_servers_or_assert(
42                                            self.servers[:self.nodes_init], self,
43                                            wait_time=self.wait_timeout, wait_if_warmup=True)
44        self.sleep(10, 'Wait some time before next load')
45        self._load_all_buckets(self.master, gen_create2, "create", 0)
46        self._wait_for_stats_all_buckets(self.servers[:self.nodes_init], timeout=self.wait_timeout * 5)
47        self._verify_stats_all_buckets(self.servers[:self.nodes_init])
48