def test_set_value_twice_in_entity(entity_factory, distributed_value_1, distributed_value_2, distributed_value_1_later, distributed_value_2_later): entity = entity_factory.createEntity("e2", Clock()) Universe.tick() Universe.tick() Universe.tick() entity.process(distributed_value_1) assert(entity.time() == 3) assert(entity.name == "e2") dv1 = entity.kvStore("dv1") assert(dv1.timestamp == 3) entity.process(distributed_value_1_later) dv1 = entity.kvStore("dv1") assert(dv1.timestamp == 110)
def test_set_value_in_entity(entity_factory, distributed_value_1): entity = entity_factory.createEntity("e2", Clock()) assert(entity.time() == 0) assert(entity.name == "e2") assert(entity.sent == 0) assert(entity.received == 0) assert(entity.kvStore.rejected == 0) entity.process(distributed_value_1) assert(entity.time() == 0) assert(entity.name == "e2") assert(entity.sent == 0) assert(entity.received == 1) assert(entity.kvStore.rejected == 0)
def test_set_value_twice_LWW(entity_factory, distributed_value_1, distributed_value_2, distributed_value_1_later, distributed_value_2_later): entity = entity_factory.createEntity("e2", Clock()) assert(entity.time() == 0) entity.kvStore.acceptableValueStrategy = LastWriteWinsAcceptableValueStrategy() Universe.tick() Universe.tick() Universe.tick() entity.process(distributed_value_2_later) assert(entity.time() == 3) assert(entity.name == "e2") dv2 = entity.kvStore("dv2") assert(dv2.timestamp == 220) entity.process(distributed_value_2) assert(entity.kvStore.rejected == 1) dv2 = entity.kvStore("dv2") assert(dv2.timestamp == 220)
def test_clock_tick2(start_time_1): clock = Clock(start_time_1) Universe.tick() Universe.tick() assert (clock.time() == 2)
def test_clock_initial(start_time_1): clock = Clock(start_time_1) assert (clock.time() == 0)
def createEntity(self, name, clock=Clock()): result = Entity(name, clock) self.entities.append(result) return result
def test_create_entity(entity_factory): entity = entity_factory.createEntity("entity1", Clock()) assert(entity.time() == 0) assert(entity.name == "entity1") assert(entity.sent == 0) assert(entity.received == 0)