Example #1
0
    def test_it(self):
        from google.cloud.firestore_v1.client import Client

        credentials = _make_credentials()
        client = Client(project="hi-projject", credentials=credentials)

        reference1 = client.document("a", "b")
        reference2 = client.document("a", "b", "c", "d")
        reference3 = client.document("a", "b")
        reference4 = client.document("f", "g")

        doc_path1 = reference1._document_path
        doc_path2 = reference2._document_path
        doc_path3 = reference3._document_path
        doc_path4 = reference4._document_path
        self.assertEqual(doc_path1, doc_path3)

        document_paths, reference_map = self._call_fut(
            [reference1, reference2, reference3, reference4])
        self.assertEqual(document_paths,
                         [doc_path1, doc_path2, doc_path3, doc_path4])
        # reference3 over-rides reference1.
        expected_map = {
            doc_path2: reference2,
            doc_path3: reference3,
            doc_path4: reference4,
        }
        self.assertEqual(reference_map, expected_map)
    def test_it(self):
        from google.cloud.firestore_v1.client import Client

        credentials = _make_credentials()
        client = Client(project="hi-projject", credentials=credentials)

        reference1 = client.document("a", "b")
        reference2 = client.document("a", "b", "c", "d")
        reference3 = client.document("a", "b")
        reference4 = client.document("f", "g")

        doc_path1 = reference1._document_path
        doc_path2 = reference2._document_path
        doc_path3 = reference3._document_path
        doc_path4 = reference4._document_path
        self.assertEqual(doc_path1, doc_path3)

        document_paths, reference_map = self._call_fut(
            [reference1, reference2, reference3, reference4]
        )
        self.assertEqual(document_paths, [doc_path1, doc_path2, doc_path3, doc_path4])
        # reference3 over-rides reference1.
        expected_map = {
            doc_path2: reference2,
            doc_path3: reference3,
            doc_path4: reference4,
        }
        self.assertEqual(reference_map, expected_map)
    def test_operation_retry_scheduling(self):
        now = datetime.datetime.now()
        one_second_from_now = now + datetime.timedelta(seconds=1)

        db = Client()
        operation = BulkWriterCreateOperation(
            reference=db.collection("asdf").document("asdf"),
            document_data={"does.not": "matter"},
        )
        operation2 = BulkWriterCreateOperation(
            reference=db.collection("different").document("document"),
            document_data={"different": "values"},
        )

        op1 = OperationRetry(operation=operation, run_at=now)
        op2 = OperationRetry(operation=operation2, run_at=now)
        op3 = OperationRetry(operation=operation, run_at=one_second_from_now)

        self.assertLess(op1, op3)
        self.assertLess(op1, op3.run_at)
        self.assertLess(op2, op3)
        self.assertLess(op2, op3.run_at)

        # Because these have the same values for `run_at`, neither should conclude
        # they are less than the other. It is okay that if we checked them with
        # greater-than evaluation, they would return True (because
        # @functools.total_ordering flips the result from __lt__). In practice,
        # this only arises for actual ties, and we don't care how actual ties are
        # ordered as we maintain the sorted list of scheduled retries.
        self.assertFalse(op1 < op2)
        self.assertFalse(op2 < op1)
Example #4
0
    def _to_sync_copy(self):
        from google.cloud.firestore_v1.client import Client

        if not getattr(self, "_sync_copy", None):
            self._sync_copy = Client(
                project=self.project,
                credentials=self._credentials,
                database=self._database,
                client_info=self._client_info,
                client_options=self._client_options,
            )
        return self._sync_copy
    def test_max_in_flight_honored(self):
        bw = NoSendBulkWriter(Client())
        # Calling this method sets up all the internal timekeeping machinery
        bw._rate_limiter.take_tokens(20)

        # Now we pretend that all tokens have been consumed. This will force us
        # to wait actual, real world milliseconds before being cleared to send more
        bw._rate_limiter._available_tokens = 0

        st = datetime.datetime.now()

        # Make a real request, subject to the actual real world clock.
        # As this request is 1/10th the per second limit, we should wait ~100ms
        bw._request_send(50)

        self.assertGreater(
            datetime.datetime.now() - st, datetime.timedelta(milliseconds=90),
        )
Example #6
0
def _make_client(project="feral-tom-cat"):
    from google.cloud.firestore_v1.client import Client

    credentials = _make_credentials()
    return Client(project=project, credentials=credentials)
Example #7
0
def _make_client(project="seventy-nine"):
    from google.cloud.firestore_v1.client import Client

    credentials = _make_credentials()
    return Client(project=project, credentials=credentials)
def _make_client():
    from google.cloud.firestore_v1.client import Client

    credentials = _make_credentials()
    return Client(project="project-project", credentials=credentials)
def make_client(project_name: typing.Optional[str] = None) -> Client:
    return Client(
        project=project_name or "project-project", credentials=make_test_credentials(),
    )
Example #10
0
def _make_client(*args, **kwargs):
    from google.cloud.firestore_v1.client import Client

    return Client(*args, **kwargs)