def test_fetch_multiple_save_updates_for_the_same_entity(self, cassandra_update_fetcher,
                                                             product_fixture_cassandra_store):
        _id = uuid.uuid4()
        timestamp = time()

        product_fixture = ProductFixture(_id=_id, timestamp=timestamp, name="The new MacBook Pro by Apple", quantity=10,
                                         description="it's amazing", price=Decimal("1999.99"), enabled=True)
        product_fixture_cassandra_store.create(product_fixture)

        product_fixture.price = Decimal("1499.99")
        product_fixture.timestamp = time()
        product_fixture_cassandra_store.update(product_fixture)

        product_fixture.description = "it' beyond amazing"
        product_fixture.enabled = False
        product_fixture.timestamp = time()
        product_fixture_cassandra_store.update(product_fixture)

        updates_iterator = cassandra_update_fetcher.fetch_updates(minimum_timestamp=timestamp)

        updates = []
        for update in updates_iterator:
            updates.append(update)

        assert len(updates) == 3

        fields = {}
        for update in updates:
            for field in update.fields:
                fields[field.name] = field.value

        assert fields["price"] == Decimal("1499.99")
        assert fields["description"] == "it' beyond amazing"
        assert fields["enabled"] is False
    def test_fetch_updates_from_the_beginning_of_time(self, elasticsearch_update_fetcher,
                                                      product_fixture_elasticsearch_store, elasticsearch_fixture_index,
                                                      product_fixture_table):

        p1 = ProductFixture(_id=uuid4(), name="navy polo shirt", description="great shirt, great price!",
                            quantity=5, price=Decimal("99.99"), enabled=True, timestamp=time())
        p2 = ProductFixture(_id=uuid4(), name="cool red shorts", description="perfect to go to the beach",
                            quantity=7, price=Decimal("49.99"), enabled=False, timestamp=time())
        p3 = ProductFixture(_id=uuid4(), name="black DC skater shoes", description="yo!",
                            quantity=10, price=Decimal("149.99"), enabled=True, timestamp=time())

        product_fixture_elasticsearch_store.create(p1)
        product_fixture_elasticsearch_store.create(p2)
        product_fixture_elasticsearch_store.create(p3)

        sleep(0.001)

        p3.description = "very cool shoes"
        p3.price = Decimal("199.99")
        p3.timestamp = time()
        product_fixture_elasticsearch_store.update(p3)

        p4 = ProductFixture(_id=uuid4(), name="black gloves", description="warm, comfortable gloves",
                            quantity=7, price=Decimal("19.99"), enabled=True, timestamp=time())
        product_fixture_elasticsearch_store.create(p4)

        p4.description = "warm, comfortable, one-size fits all gloves"
        p4.quantity = 19
        p4.timestamp = time()
        product_fixture_elasticsearch_store.update(p4)

        p1.quantity = 10
        p1.timestamp = time()
        product_fixture_elasticsearch_store.update(p1)

        products = (p1, p2, p3, p4)

        updates_iterator = elasticsearch_update_fetcher.fetch_updates()
        product_updates = self.filter_documents_by_type(
            elasticsearch_fixture_index, product_fixture_table, updates_iterator)

        assert len(product_updates) == len(products)

        updates_by_key = self.group_updates_by_key(product_updates)

        for product in products:
            update = updates_by_key[product.key]
            assert abs(product.timestamp - update.timestamp) < 0.001
            assert product.name == update.get_field_value("name")
            assert product.description == update.get_field_value("description")
            assert product.price == Decimal(update.get_field_value("price"))
            assert product.enabled == update.get_field_value("enabled")
            assert product.quantity == update.get_field_value("quantity")
    def test_fetch_updates_with_minimum_time(self, elasticsearch_update_fetcher,
                                             product_fixture_elasticsearch_store, elasticsearch_fixture_index,
                                             product_fixture_table):

        before_minimum_timestamp = time()

        p1 = ProductFixture(_id=uuid4(), name="navy polo shirt", description="great shirt, great price!",
                            quantity=5, price=Decimal("99.99"), enabled=True, timestamp=before_minimum_timestamp)
        p2 = ProductFixture(_id=uuid4(), name="cool red shorts", description="perfect to go to the beach",
                            quantity=7, price=Decimal("49.99"), enabled=False, timestamp=before_minimum_timestamp)
        p3 = ProductFixture(_id=uuid4(), name="black DC skater shoes", description="yo!",
                            quantity=10, price=Decimal("149.99"), enabled=True, timestamp=before_minimum_timestamp)

        product_fixture_elasticsearch_store.create(p1)
        product_fixture_elasticsearch_store.create(p2)
        product_fixture_elasticsearch_store.create(p3)

        sleep(0.001)

        minimum_timestamp = time()

        p3.description = "very cool shoes"
        p3.price = Decimal("199.99")
        p3.timestamp = time()
        product_fixture_elasticsearch_store.update(p3)

        p4 = ProductFixture(_id=uuid4(), name="black gloves", description="warm, comfortable gloves",
                            quantity=7, price=Decimal("19.99"), enabled=True, timestamp=time())
        product_fixture_elasticsearch_store.create(p4)

        p4.description = "warm, comfortable, one-size fits all gloves"
        p4.quantity = 19
        product_fixture_elasticsearch_store.update(p4)

        p2.quantity = 10
        p2.timestamp = time()
        product_fixture_elasticsearch_store.update(p2)

        updates_iterator = elasticsearch_update_fetcher.fetch_updates(minimum_timestamp)
        product_updates = self.filter_documents_by_type(
            elasticsearch_fixture_index, product_fixture_table, updates_iterator)

        assert len(product_updates) == 3

        updates_by_key = self.group_updates_by_key(product_updates)

        assert p2.key in updates_by_key
        assert p3.key in updates_by_key
        assert p4.key in updates_by_key
        assert p1.key not in updates_by_key
    def test_partial_update(self, product_fixture_elasticsearch_store):
        _id = uuid4()

        original_name = "jeans"
        original_description = "cool jeans"
        original_quantity = 5

        product = ProductFixture(_id=_id,
                                 timestamp=time(),
                                 name=original_name,
                                 description=original_description,
                                 quantity=original_quantity)
        product_fixture_elasticsearch_store.create(product)

        updated_description = "red t-shirt"
        updated_quantity = 10

        product.description = updated_description
        product.quantity = updated_quantity
        product.timestamp = time()
        product_fixture_elasticsearch_store.update(product)

        read_product = product_fixture_elasticsearch_store.read(_id)
        assert read_product.name == original_name
        assert read_product.description == updated_description
        assert read_product.quantity == updated_quantity
    def test_full_update(self, product_fixture_elasticsearch_store):
        _id = uuid4()

        product = ProductFixture(_id=_id,
                                 timestamp=time(),
                                 name="jeans",
                                 description="cool jeans",
                                 quantity=5,
                                 price=Decimal("49.99"),
                                 enabled=False)
        product_fixture_elasticsearch_store.create(product)

        updated_name = "shirt"
        updated_description = "red t-shirt"
        updated_quantity = 10
        updated_price = Decimal("99.99")
        updated_enabled = True

        product.name = updated_name
        product.description = updated_description
        product.quantity = updated_quantity
        product.price = updated_price
        product.enabled = updated_enabled
        product.timestamp = time()
        product_fixture_elasticsearch_store.update(product)

        read_product = product_fixture_elasticsearch_store.read(_id)
        assert read_product.name == updated_name
        assert read_product.description == updated_description
        assert read_product.quantity == updated_quantity
        assert read_product.price == updated_price
        assert read_product.enabled == updated_enabled
    def test_full_update(self, product_fixture_elasticsearch_store):
        _id = uuid4()

        product = ProductFixture(_id=_id, timestamp=time(), name="jeans", description="cool jeans", quantity=5,
                                 price=Decimal("49.99"), enabled=False)
        product_fixture_elasticsearch_store.create(product)

        updated_name = "shirt"
        updated_description = "red t-shirt"
        updated_quantity = 10
        updated_price = Decimal("99.99")
        updated_enabled = True

        product.name = updated_name
        product.description = updated_description
        product.quantity = updated_quantity
        product.price = updated_price
        product.enabled = updated_enabled
        product.timestamp = time()
        product_fixture_elasticsearch_store.update(product)

        read_product = product_fixture_elasticsearch_store.read(_id)
        assert read_product.name == updated_name
        assert read_product.description == updated_description
        assert read_product.quantity == updated_quantity
        assert read_product.price == updated_price
        assert read_product.enabled == updated_enabled
Ejemplo n.º 7
0
    def test_fetch_multiple_save_updates_for_the_same_entity(
            self, cassandra_update_fetcher, product_fixture_cassandra_store):
        _id = uuid.uuid4()
        timestamp = time()

        product_fixture = ProductFixture(_id=_id,
                                         timestamp=timestamp,
                                         name="The new MacBook Pro by Apple",
                                         quantity=10,
                                         description="it's amazing",
                                         price=Decimal("1999.99"),
                                         enabled=True)
        product_fixture_cassandra_store.create(product_fixture)

        product_fixture.price = Decimal("1499.99")
        product_fixture.timestamp = time()
        product_fixture_cassandra_store.update(product_fixture)

        product_fixture.description = "it' beyond amazing"
        product_fixture.enabled = False
        product_fixture.timestamp = time()
        product_fixture_cassandra_store.update(product_fixture)

        updates_iterator = cassandra_update_fetcher.fetch_updates(
            minimum_timestamp=timestamp)

        updates = []
        for update in updates_iterator:
            updates.append(update)

        assert len(updates) == 3

        fields = {}
        for update in updates:
            for field in update.fields:
                fields[field.name] = field.value

        assert fields["price"] == Decimal("1499.99")
        assert fields["description"] == "it' beyond amazing"
        assert fields["enabled"] is False
    def test_do_not_apply_update_to_existing_document_if_it_was_already_updated(
            self, update_applier, cassandra_fixture_keyspace,
            product_fixture_table, product_fixture_cassandra_store):

        keyspace = cassandra_fixture_keyspace
        table = product_fixture_table
        _id = uuid4()

        original_name = "jeans"
        original_description = "cool jeans"
        original_quantity = 5

        product = ProductFixture(_id=_id,
                                 timestamp=time(),
                                 name=original_name,
                                 description=original_description,
                                 quantity=original_quantity)
        product_fixture_cassandra_store.create(product)

        updated_name = "t-shirt"
        updated_description = "cool red t-shirt"
        updated_quantity = 10

        obsolete_update = build_update(namespace=keyspace,
                                       table=table,
                                       key=str(_id),
                                       timestamp=time(),
                                       fields=build_fields(
                                           name=updated_name,
                                           description=updated_description,
                                           quantity=updated_quantity))

        sleep(0.001)

        more_recently_updated_name = "shoes"
        more_recently_updated_description = "skater shoes"

        product.name = more_recently_updated_name
        product.description = more_recently_updated_description
        product.timestamp = time()
        product_fixture_cassandra_store.update(product)

        update_applier.apply_update(obsolete_update)

        product = product_fixture_cassandra_store.read(_id)
        assert product.name == more_recently_updated_name
        assert product.description == more_recently_updated_description
        assert product.quantity == original_quantity
    def test_do_not_apply_update_to_existing_document_if_it_was_already_updated(self, update_applier,
            elasticsearch_fixture_index, product_fixture_table, product_fixture_elasticsearch_store):

        _index = elasticsearch_fixture_index
        _type = product_fixture_table
        _id = uuid4()

        original_name = "jeans"
        original_description = "cool jeans"
        original_quantity = 5

        product = ProductFixture(_id=_id, timestamp=time(),
                                 name=original_name, description=original_description, quantity=original_quantity)
        product_fixture_elasticsearch_store.create(product)

        updated_name = "t-shirt"
        updated_description = "cool red t-shirt"
        updated_quantity = 10

        obsolete_update = build_update(namespace=_index, table=_type, key=str(_id), timestamp=time(),
                                       fields=build_fields(name=updated_name,
                                                           description=updated_description,
                                                           quantity=updated_quantity))

        sleep(0.001)

        more_recently_updated_name = "shoes"
        more_recently_updated_description = "skater shoes"

        product.name = more_recently_updated_name
        product.description = more_recently_updated_description
        product.timestamp = time()
        product_fixture_elasticsearch_store.update(product)

        update_applier.apply_update(obsolete_update)

        product = product_fixture_elasticsearch_store.read(_id)
        assert product.name == more_recently_updated_name
        assert product.description == more_recently_updated_description
        assert product.quantity == original_quantity
    def test_partial_update(self, product_fixture_elasticsearch_store):
        _id = uuid4()

        original_name = "jeans"
        original_description = "cool jeans"
        original_quantity = 5

        product = ProductFixture(_id=_id, timestamp=time(), name=original_name,
                                 description=original_description, quantity=original_quantity)
        product_fixture_elasticsearch_store.create(product)

        updated_description = "red t-shirt"
        updated_quantity = 10

        product.description = updated_description
        product.quantity = updated_quantity
        product.timestamp = time()
        product_fixture_elasticsearch_store.update(product)

        read_product = product_fixture_elasticsearch_store.read(_id)
        assert read_product.name == original_name
        assert read_product.description == updated_description
        assert read_product.quantity == updated_quantity
Ejemplo n.º 11
0
    def test_fetch_updates_with_minimum_time(
            self, elasticsearch_update_fetcher,
            product_fixture_elasticsearch_store, elasticsearch_fixture_index,
            product_fixture_table):

        before_minimum_timestamp = time()

        p1 = ProductFixture(_id=uuid4(),
                            name="navy polo shirt",
                            description="great shirt, great price!",
                            quantity=5,
                            price=Decimal("99.99"),
                            enabled=True,
                            timestamp=before_minimum_timestamp)
        p2 = ProductFixture(_id=uuid4(),
                            name="cool red shorts",
                            description="perfect to go to the beach",
                            quantity=7,
                            price=Decimal("49.99"),
                            enabled=False,
                            timestamp=before_minimum_timestamp)
        p3 = ProductFixture(_id=uuid4(),
                            name="black DC skater shoes",
                            description="yo!",
                            quantity=10,
                            price=Decimal("149.99"),
                            enabled=True,
                            timestamp=before_minimum_timestamp)

        product_fixture_elasticsearch_store.create(p1)
        product_fixture_elasticsearch_store.create(p2)
        product_fixture_elasticsearch_store.create(p3)

        sleep(0.001)

        minimum_timestamp = time()

        p3.description = "very cool shoes"
        p3.price = Decimal("199.99")
        p3.timestamp = time()
        product_fixture_elasticsearch_store.update(p3)

        p4 = ProductFixture(_id=uuid4(),
                            name="black gloves",
                            description="warm, comfortable gloves",
                            quantity=7,
                            price=Decimal("19.99"),
                            enabled=True,
                            timestamp=time())
        product_fixture_elasticsearch_store.create(p4)

        p4.description = "warm, comfortable, one-size fits all gloves"
        p4.quantity = 19
        product_fixture_elasticsearch_store.update(p4)

        p2.quantity = 10
        p2.timestamp = time()
        product_fixture_elasticsearch_store.update(p2)

        updates_iterator = elasticsearch_update_fetcher.fetch_updates(
            minimum_timestamp)
        product_updates = self.filter_documents_by_type(
            elasticsearch_fixture_index, product_fixture_table,
            updates_iterator)

        assert len(product_updates) == 3

        updates_by_key = self.group_updates_by_key(product_updates)

        assert p2.key in updates_by_key
        assert p3.key in updates_by_key
        assert p4.key in updates_by_key
        assert p1.key not in updates_by_key
Ejemplo n.º 12
0
    def test_fetch_updates_from_the_beginning_of_time(
            self, elasticsearch_update_fetcher,
            product_fixture_elasticsearch_store, elasticsearch_fixture_index,
            product_fixture_table):

        p1 = ProductFixture(_id=uuid4(),
                            name="navy polo shirt",
                            description="great shirt, great price!",
                            quantity=5,
                            price=Decimal("99.99"),
                            enabled=True,
                            timestamp=time())
        p2 = ProductFixture(_id=uuid4(),
                            name="cool red shorts",
                            description="perfect to go to the beach",
                            quantity=7,
                            price=Decimal("49.99"),
                            enabled=False,
                            timestamp=time())
        p3 = ProductFixture(_id=uuid4(),
                            name="black DC skater shoes",
                            description="yo!",
                            quantity=10,
                            price=Decimal("149.99"),
                            enabled=True,
                            timestamp=time())

        product_fixture_elasticsearch_store.create(p1)
        product_fixture_elasticsearch_store.create(p2)
        product_fixture_elasticsearch_store.create(p3)

        sleep(0.001)

        p3.description = "very cool shoes"
        p3.price = Decimal("199.99")
        p3.timestamp = time()
        product_fixture_elasticsearch_store.update(p3)

        p4 = ProductFixture(_id=uuid4(),
                            name="black gloves",
                            description="warm, comfortable gloves",
                            quantity=7,
                            price=Decimal("19.99"),
                            enabled=True,
                            timestamp=time())
        product_fixture_elasticsearch_store.create(p4)

        p4.description = "warm, comfortable, one-size fits all gloves"
        p4.quantity = 19
        p4.timestamp = time()
        product_fixture_elasticsearch_store.update(p4)

        p1.quantity = 10
        p1.timestamp = time()
        product_fixture_elasticsearch_store.update(p1)

        products = (p1, p2, p3, p4)

        updates_iterator = elasticsearch_update_fetcher.fetch_updates()
        product_updates = self.filter_documents_by_type(
            elasticsearch_fixture_index, product_fixture_table,
            updates_iterator)

        assert len(product_updates) == len(products)

        updates_by_key = self.group_updates_by_key(product_updates)

        for product in products:
            update = updates_by_key[product.key]
            assert abs(product.timestamp - update.timestamp) < 0.001
            assert product.name == update.get_field_value("name")
            assert product.description == update.get_field_value("description")
            assert product.price == Decimal(update.get_field_value("price"))
            assert product.enabled == update.get_field_value("enabled")
            assert product.quantity == update.get_field_value("quantity")