Пример #1
0
    def test(self):
        r = self.connection(_lv.DescribeTable("Aaa"))

        self.assertDateTimeIsReasonable(r.table.creation_date_time)
        self.assertEqual(r.table.attribute_definitions[0].attribute_name, "h")
        self.assertEqual(r.table.attribute_definitions[0].attribute_type, "S")
        self.assertEqual(r.table.global_secondary_indexes, None)
        self.assertEqual(r.table.item_count, 0)
        self.assertEqual(r.table.key_schema[0].attribute_name, "h")
        self.assertEqual(r.table.key_schema[0].key_type, "HASH")
        self.assertEqual(r.table.local_secondary_indexes, None)
        self.assertEqual(
            r.table.provisioned_throughput.last_decrease_date_time,
            datetime.datetime(1970, 1, 1))
        self.assertEqual(
            r.table.provisioned_throughput.last_increase_date_time,
            datetime.datetime(1970, 1, 1))
        self.assertEqual(
            r.table.provisioned_throughput.number_of_decreases_today, 0)
        self.assertEqual(r.table.provisioned_throughput.read_capacity_units, 1)
        self.assertEqual(r.table.provisioned_throughput.write_capacity_units,
                         2)
        self.assertEqual(r.table.table_name, "Aaa")
        self.assertEqual(r.table.table_size_bytes, 0)
        self.assertEqual(r.table.table_status, "ACTIVE")
Пример #2
0
def wait_for_table_deletion(connection, table):
    """
    Make :class:`.DescribeTable` actions until a :exc:`.ResourceNotFoundException` is raised.
    Useful after :class:`.DeleteTable` action.

    .. testsetup::

        table = "LowVoltage.Tests.Doc.WaitForTableDeletion.1"
        connection(CreateTable(table).hash_key("h", STRING).provisioned_throughput(1, 1))
        wait_for_table_activation(connection, table)

    >>> connection(DeleteTable(table)).table_description.table_status
    u'DELETING'
    >>> wait_for_table_deletion(connection, table)
    >>> connection(DescribeTable(table))
    Traceback (most recent call last):
      ...
    LowVoltage.exceptions.ResourceNotFoundException: ...
    """

    while True:
        try:
            connection(_lv.DescribeTable(table))
            time.sleep(3)
        except _lv.ResourceNotFoundException:
            break
Пример #3
0
    def test_delete_and_create_gsi(self):
        r = self.connection(
            _lv.UpdateTable("Aaa").delete_global_secondary_index("the_gsi"))
        self.assertEqual(
            r.table_description.global_secondary_indexes[0].index_status,
            "DELETING")

        _lv.wait_for_table_activation(self.connection, "Aaa")

        r = self.connection(_lv.DescribeTable("Aaa"))
        self.assertEqual(r.table.global_secondary_indexes, None)
        self.assertEqual(
            len(r.table.attribute_definitions),
            1)  # The previous definition of attribute "hh" has disapeared.

        r = self.connection(
            _lv.UpdateTable("Aaa").create_global_secondary_index(
                "new_gsi").provisioned_throughput(1, 2).hash_key(
                    "nh", _lv.NUMBER).project_all())

        self.assertEqual(
            r.table_description.global_secondary_indexes[0].
            provisioned_throughput.read_capacity_units, 1)
        self.assertEqual(
            r.table_description.global_secondary_indexes[0].
            provisioned_throughput.write_capacity_units, 2)
        self.assertEqual(
            r.table_description.global_secondary_indexes[0].key_schema[0].
            attribute_name, "nh")
        self.assertEqual(
            r.table_description.global_secondary_indexes[0].key_schema[0].
            key_type, "HASH")
        self.assertEqual(len(r.table_description.attribute_definitions), 2)
Пример #4
0
def _describe(connection, table):
    try:
        return connection(_lv.DescribeTable(table)).table
    except _lv.ResourceNotFoundException:
        # DescribeTable seems to perform an eventually consistent read.
        # So from time to time you create a table (on server A), then ask for its description
        # (on server B) and server B doesn't know yet it exists.
        # Seen in https://travis-ci.org/jacquev6/LowVoltage/jobs/61754722#L962
        return None
 def test(self):
     self.connection(
         _lv.CreateTable("Aaa").hash_key("h",
                                         _lv.STRING).provisioned_throughput(
                                             1, 1))
     _lv.wait_for_table_activation(self.connection, "Aaa")
     self.assertEqual(
         self.connection(_lv.DescribeTable("Aaa")).table.table_status,
         "ACTIVE")
 def test(self):
     self.connection(
         _lv.CreateTable(self.table).hash_key("tab_h", _lv.STRING).
         range_key("tab_r", _lv.NUMBER).provisioned_throughput(
             1, 1).global_secondary_index("gsi").hash_key(
                 "gsi_h", _lv.STRING).range_key(
                     "gsi_r",
                     _lv.NUMBER).project_all().provisioned_throughput(1, 1))
     _lv.wait_for_table_activation(self.connection, self.table)
     r = self.connection(_lv.DescribeTable(self.table))
     self.assertEqual(r.table.table_status, "ACTIVE")
     self.assertEqual(r.table.global_secondary_indexes[0].index_status,
                      "ACTIVE")
Пример #7
0
 def test(self):
     self.connection(_lv.DeleteTable(self.table))
     _lv.wait_for_table_deletion(self.connection, self.table)
     with self.assertRaises(_lv.ResourceNotFoundException):
         self.connection(_lv.DescribeTable(self.table))
Пример #8
0
def global_setup():
    connection = _lv.Connection("us-west-2", _lv.EnvironmentCredentials())

    table1 = "LowVoltage.Tests.Doc.1"
    table2 = "LowVoltage.Tests.Doc.2"

    try:
        connection(_lv.DescribeTable(table1))
    except _lv.ResourceNotFoundException:
        connection(
            _lv.CreateTable(table).hash_key(
                "h", _lv.NUMBER).provisioned_throughput(
                    1, 1).global_secondary_index("gsi").hash_key(
                        "gh", _lv.NUMBER).range_key(
                            "gr", _lv.NUMBER).provisioned_throughput(
                                1, 1).project_all())

    try:
        connection(_lv.DescribeTable(table2))
    except _lv.ResourceNotFoundException:
        connection(
            _lv.CreateTable(table2).hash_key("h", _lv.NUMBER).range_key(
                "r1", _lv.NUMBER).provisioned_throughput(
                    1, 1).local_secondary_index("lsi").hash_key(
                        "h", _lv.NUMBER).range_key("r2",
                                                   _lv.NUMBER).project_all())

    _lv.wait_for_table_activation(connection, table1)
    _lv.batch_put_item(
        connection,
        table1,
        [{
            "h": h,
            "gh": h * h,
            "gr": 10 - 2 * h
        } for h in range(7)],
    )

    _lv.wait_for_table_activation(connection, table1)
    _lv.batch_put_item(
        connection,
        table1,
        [{
            "h": h,
            "a": 0
        } for h in range(7, 10)],
    )

    _lv.wait_for_table_activation(connection, table2)
    _lv.batch_put_item(
        connection,
        table2,
        [{
            "h": h,
            "r1": 0,
            "r2": 0
        } for h in range(10)],
    )

    _lv.batch_put_item(
        connection,
        table2,
        [{
            "h": 42,
            "r1": r1,
            "r2": 10 - r1
        } for r1 in range(6)],
    )

    _lv.batch_put_item(
        connection,
        table2,
        [{
            "h": 42,
            "r1": r1
        } for r1 in range(6, 10)],
    )

    return connection, table1, table2