Skip to content

Commit d45af14

Browse files
authored
Skip tests when a newer server is expected (#386)
On certain tests, a newer server might be required to test functionality. Formerly, we were using attributes to distinguish such tests but this way, it is easier to handle all cases. Also, removed some unneeded compatibility code.
1 parent ea1058e commit d45af14

File tree

8 files changed

+24
-26
lines changed

8 files changed

+24
-26
lines changed

tests/integration/backward_compatible/client_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from hazelcast.client import HazelcastClient
55
from hazelcast.lifecycle import LifecycleState
66
from tests.hzrc.ttypes import Lang
7-
from tests.integration.backward_compatible.util import get_current_timestamp
7+
from tests.util import get_current_timestamp
88

99

1010
class ClientTest(HazelcastTestCase):

tests/integration/backward_compatible/proxy/cp/atomic_long_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from hazelcast.errors import DistributedObjectDestroyedError
22
from hazelcast.serialization.api import IdentifiedDataSerializable
33
from tests.integration.backward_compatible.proxy.cp import CPTestCase
4-
from tests.util import set_attr
4+
from tests.util import mark_server_version_at_least
55

66

77
class Multiplication(IdentifiedDataSerializable):
@@ -106,30 +106,30 @@ def test_set(self):
106106
self.assertIsNone(self.atomic_long.set(42))
107107
self.assertEqual(42, self.atomic_long.get())
108108

109-
@set_attr(min_server_version="4.1")
110109
def test_alter(self):
111110
# the class is defined in the 4.1 JAR
111+
mark_server_version_at_least(self, self.client, "4.1")
112112
self.atomic_long.set(2)
113113
self.assertIsNone(self.atomic_long.alter(Multiplication(5)))
114114
self.assertEqual(10, self.atomic_long.get())
115115

116-
@set_attr(min_server_version="4.1")
117116
def test_alter_and_get(self):
118117
# the class is defined in the 4.1 JAR
118+
mark_server_version_at_least(self, self.client, "4.1")
119119
self.atomic_long.set(-3)
120120
self.assertEqual(-9, self.atomic_long.alter_and_get(Multiplication(3)))
121121
self.assertEqual(-9, self.atomic_long.get())
122122

123-
@set_attr(min_server_version="4.1")
124123
def test_get_and_alter(self):
125124
# the class is defined in the 4.1 JAR
125+
mark_server_version_at_least(self, self.client, "4.1")
126126
self.atomic_long.set(123)
127127
self.assertEqual(123, self.atomic_long.get_and_alter(Multiplication(-1)))
128128
self.assertEqual(-123, self.atomic_long.get())
129129

130-
@set_attr(min_server_version="4.1")
131130
def test_apply(self):
132131
# the class is defined in the 4.1 JAR
132+
mark_server_version_at_least(self, self.client, "4.1")
133133
self.atomic_long.set(42)
134134
self.assertEqual(84, self.atomic_long.apply(Multiplication(2)))
135135
self.assertEqual(42, self.atomic_long.get())

tests/integration/backward_compatible/proxy/cp/atomic_reference_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from tests.integration.backward_compatible.util import write_string_to_output
55
from tests.integration.backward_compatible.proxy.cp import CPTestCase
6-
from tests.util import set_attr
6+
from tests.util import mark_server_version_at_least
77

88

99
class AppendString(IdentifiedDataSerializable):
@@ -108,37 +108,37 @@ def test_contains(self):
108108
self.assertFalse(self.ref.contains("42"))
109109
self.assertTrue(self.ref.contains(None))
110110

111-
@set_attr(min_server_version="4.1")
112111
def test_alter(self):
113112
# the class is defined in the 4.1 JAR
113+
mark_server_version_at_least(self, self.client, "4.1")
114114
self.ref.set("hey")
115115
self.assertIsNone(self.ref.alter(AppendString("123")))
116116
self.assertEqual("hey123", self.ref.get())
117117

118-
@set_attr(min_server_version="4.1")
119118
def test_alter_with_incompatible_types(self):
120119
# the class is defined in the 4.1 JAR
120+
mark_server_version_at_least(self, self.client, "4.1")
121121
self.ref.set(42)
122122
with self.assertRaises(ClassCastError):
123123
self.ref.alter(AppendString("."))
124124

125-
@set_attr(min_server_version="4.1")
126125
def test_alter_and_get(self):
127126
# the class is defined in the 4.1 JAR
127+
mark_server_version_at_least(self, self.client, "4.1")
128128
self.ref.set("123")
129129
self.assertEqual("123...", self.ref.alter_and_get(AppendString("...")))
130130
self.assertEqual("123...", self.ref.get())
131131

132-
@set_attr(min_server_version="4.1")
133132
def test_get_and_alter(self):
134133
# the class is defined in the 4.1 JAR
134+
mark_server_version_at_least(self, self.client, "4.1")
135135
self.ref.set("hell")
136136
self.assertEqual("hell", self.ref.get_and_alter(AppendString("o")))
137137
self.assertEqual("hello", self.ref.get())
138138

139-
@set_attr(min_server_version="4.1")
140139
def test_apply(self):
141140
# the class is defined in the 4.1 JAR
141+
mark_server_version_at_least(self, self.client, "4.1")
142142
self.ref.set("hell")
143143
self.assertEqual("hello", self.ref.apply(AppendString("o")))
144144
self.assertEqual("hell", self.ref.get())

tests/integration/backward_compatible/proxy/cp/count_down_latch_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
from hazelcast.future import ImmediateExceptionFuture
55
from hazelcast.util import AtomicInteger
66
from tests.integration.backward_compatible.proxy.cp import CPTestCase
7-
from tests.integration.backward_compatible.util import get_current_timestamp
8-
from tests.util import random_string
7+
from tests.util import get_current_timestamp, random_string
98

109

1110
inf = 2 ** 31 - 1

tests/integration/backward_compatible/proxy/cp/semaphore_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
IllegalStateError,
1010
)
1111
from tests.integration.backward_compatible.proxy.cp import CPTestCase
12-
from tests.integration.backward_compatible.util import get_current_timestamp
13-
from tests.util import random_string
12+
from tests.util import get_current_timestamp, random_string
1413

1514
SEMAPHORE_TYPES = [
1615
"sessionless",

tests/integration/backward_compatible/statistics_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from hazelcast.statistics import Statistics
77
from tests.base import HazelcastTestCase
88
from tests.hzrc.ttypes import Lang
9-
from tests.integration.backward_compatible.util import get_current_timestamp
10-
from tests.util import random_string
9+
from tests.util import get_current_timestamp, random_string
1110

1211

1312
class StatisticsTest(HazelcastTestCase):

tests/integration/backward_compatible/util.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
import time
2-
3-
try:
4-
from tests.util import get_current_timestamp
5-
except ImportError:
6-
get_current_timestamp = time.time
7-
8-
91
def read_string_from_input(inp):
102
if hasattr(inp, "read_string"):
113
return inp.read_string()

tests/util.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from uuid import uuid4
55
from hazelcast.config import SSLProtocol
6+
from hazelcast.util import calculate_version
67

78
# time.monotonic() is more consistent since it uses cpu clock rather than system clock. Use it if available.
89
if hasattr(time, "monotonic"):
@@ -88,6 +89,14 @@ def wrap_ob(ob):
8889
return wrap_ob
8990

9091

92+
def mark_server_version_at_least(test, client, expected_version):
93+
connection = client._connection_manager.get_random_connection()
94+
server_version = connection.server_version
95+
expected_version = calculate_version(expected_version)
96+
if server_version < expected_version:
97+
test.skipTest("Expected a newer server")
98+
99+
91100
def open_connection_to_address(client, uuid):
92101
key = generate_key_owned_by_instance(client, uuid)
93102
m = client.get_map(random_string()).blocking()

0 commit comments

Comments
 (0)