Ejemplo n.º 1
0
    def run(self):
        coordinator = self._coordinator
        counter = self._counter
        test_map = coordinator.test_map
        processor = SimpleEntryProcessor("test")

        while coordinator.should_continue_tests():
            key = str(random.randint(0, ENTRY_COUNT))
            value = str(random.randint(0, ENTRY_COUNT))
            operation = random.randint(0, 100)
            try:
                if operation < 30:
                    test_map.get(key)
                elif operation < 60:
                    test_map.put(key, value)
                elif operation < 80:
                    test_map.values(between("this", 0, 10))
                else:
                    test_map.execute_on_key(key, processor)

                counter.increment()
            except:
                coordinator.notify_error()
                logging.exception("Unexpected error occurred in thread %s", self)
                return
Ejemplo n.º 2
0
    def run(stats):
        end_time = get_current_timestamp() + hour_limit * 60 * 60
        while get_current_timestamp() < end_time:
            if test_failed[0]:
                return  # Some other thread failed, no need to continue the test

            key = str(random.randint(0, ENTRY_COUNT))
            value = str(random.randint(0, ENTRY_COUNT))
            operation = random.randint(0, 100)
            try:
                if operation < 30:
                    test_map.get(key)
                elif operation < 60:
                    test_map.put(key, value)
                elif operation < 80:
                    test_map.values(between("this", 0, 10))
                else:
                    test_map.execute_on_key(key, processor)

                stats.increment_operation_count()
            except:
                test_failed[0] = True
                logging.exception("Unexpected error occurred")
                return
Ejemplo n.º 3
0
    def test_between(self):
        self.fill_map_numeric()

        predicate = between("this", 1, 20)
        self.assertCountEqual(self.map.key_set(predicate), list(range(1, 21)))
 "ArrayList": [None, _non_null_list],
 "LinkedList": [None, _non_null_list],
 "TruePredicate":
 predicate.true(),
 "FalsePredicate":
 predicate.false(),
 "SqlPredicate":
 predicate.sql(_sql_string),
 "EqualPredicate":
 predicate.equal(_sql_string, REFERENCE_OBJECTS["Integer"]),
 "NotEqualPredicate":
 predicate.not_equal(_sql_string, REFERENCE_OBJECTS["Integer"]),
 "GreaterLessPredicate":
 predicate.greater(_sql_string, REFERENCE_OBJECTS["Integer"]),
 "BetweenPredicate":
 predicate.between(_sql_string, REFERENCE_OBJECTS["Integer"],
                   REFERENCE_OBJECTS["Integer"]),
 "LikePredicate":
 predicate.like(_sql_string, _sql_string),
 "ILikePredicate":
 predicate.ilike(_sql_string, _sql_string),
 "InPredicate":
 predicate.in_(_sql_string, REFERENCE_OBJECTS["Integer"],
               REFERENCE_OBJECTS["Integer"]),
 "RegexPredicate":
 predicate.regex(_sql_string, _sql_string),
 "AndPredicate":
 predicate.and_(
     predicate.sql(_sql_string),
     predicate.equal(_sql_string, REFERENCE_OBJECTS["Integer"]),
     predicate.not_equal(_sql_string, REFERENCE_OBJECTS["Integer"]),
     predicate.greater(_sql_string, REFERENCE_OBJECTS["Integer"]),
Ejemplo n.º 5
0
                                                         self.age, self.active)


def generate_users(users):
    users.put("Rod", User("Rod", 19, True))
    users.put("Jane", User("Jane", 20, True))
    users.put("Freddy", User("Freddy", 23, True))


# Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
hz = hazelcast.HazelcastClient(
    portable_factories={User.FACTORY_ID: {
        User.CLASS_ID: User
    }})
# Get a Distributed Map called "users"
users_map = hz.get_map("users").blocking()
# Add some users to the Distributed Map
generate_users(users_map)
# Create a Predicate from a String (a SQL like Where clause)
sql_query = sql("active AND age BETWEEN 18 AND 21)")
# Creating the same Predicate as above but with a builder
criteria_query = and_(equal("active", True), between("age", 18, 21))
# Get result collections using the two different Predicates
result1 = users_map.values(sql_query)
result2 = users_map.values(criteria_query)
# Print out the results
print(result1)
print(result2)
# Shutdown this Hazelcast Client
hz.shutdown()
Ejemplo n.º 6
0
 def test_between(self):
     predicate = between("this", 1, 20)
     self.assertEqual(str(predicate),
                      "BetweenPredicate(attribute='this', from=1, to=20)")
Ejemplo n.º 7
0
# It also uses the custom comparator we have
# written and sorts the values in ascending
# order of age.
paging_predicate = predicate.paging(
    predicate=predicate.true(),
    page_size=10,
    comparator=AgeComparator(),
)
print(students.values(paging_predicate))

# Set up the next page and fetch it.
paging_predicate.next_page()
print(students.values(paging_predicate))

# This time, we will fetch students with the
# student_id between 10 to 40 with the page size
# of 5. We will also make use of the custom comparator
# and sort the results in descending order of age.
paging_predicate = predicate.paging(
    predicate=predicate.between("student_id", 10, 40),
    page_size=5,
    comparator=AgeComparator(reverse=True),
)
print(students.values(paging_predicate))

# Set up the next page and fetch it.
paging_predicate.next_page()
print(students.values(paging_predicate))

client.shutdown()
import hazelcast

from hazelcast.predicate import between

client = hazelcast.HazelcastClient()

predicate_map = client.get_map("predicate-map").blocking()
for i in range(10):
    predicate_map.put("key" + str(i), i)

predicate = between("this", 3, 5)

entry_set = predicate_map.entry_set(predicate)

for key, value in entry_set:
    print("%s -> %s" % (key, value))

client.shutdown()