Пример #1
0
 def testLengthIsOneAfterAddSubject(self):
     """
     Adding a subject to a new SubjectStore results in SubjectStore with
     length one.
     """
     ss = SubjectStore()
     subject = Subject(AARead('id', 'AA'))
     ss.add(subject)
     self.assertEqual(1, len(ss))
Пример #2
0
 def testAddSubjectWithIndex(self):
     """
     Adding one subject to a SubjectStore and giving a subject index
     must return the expected result.
     """
     subject = Subject(AARead('id', 'AA'))
     preExisting, subjectIndex = SubjectStore().add(subject, '3')
     self.assertFalse(preExisting)
     self.assertEqual('3', subjectIndex)
Пример #3
0
 def testLengthIsOneAfterAddSameSubjectTwice(self):
     """
     Adding a subject to a new SubjectStore twice (with an identical index)
     results in SubjectStore with length one.
     """
     ss = SubjectStore()
     subject = Subject(AARead('id', 'AA'))
     ss.add(subject)
     ss.add(subject)
     self.assertEqual(1, len(ss))
Пример #4
0
 def testAddTwoSubjectsWithIndex(self):
     """
     Adding two subjects to a SubjectStore and giving their indices
     must have the expected result.
     """
     ss = SubjectStore()
     subject1 = Subject(AARead('id1', 'AA'))
     subject2 = Subject(AARead('id2', 'AA'))
     ss.add(subject1, '1')
     ss.add(subject2, '2')
     self.assertEqual(2, len(ss))
Пример #5
0
 def testSaveRestoreEmpty(self):
     """
     After a save/restore of an empty subject store, the result must be as
     expected.
     """
     ss = SubjectStore()
     fp = StringIO()
     ss.save(fp)
     fp.seek(0)
     ss = SubjectStore.restore(fp)
     self.assertEqual(0, len(ss))
Пример #6
0
 def testGetSubjects(self):
     """
     getSubjects must return the expected result.
     """
     ss = SubjectStore()
     subject1 = Subject(AARead('id1', 'AA'))
     subject2 = Subject(AARead('id2', 'CC'))
     ss.add(subject1, '1')
     ss.add(subject2, '2')
     result = set(ss.getSubjects())
     self.assertEqual(set([subject1, subject2]), result)
Пример #7
0
 def testAddSubjectTwiceWithSameIndex(self):
     """
     Adding a subject to a SubjectStore and giving a subject index
     and then re-adding it with the same index must return the expected
     result.
     """
     subject = Subject(AARead('id', 'AA'))
     ss = SubjectStore()
     ss.add(subject, '3')
     preExisting, subjectIndex = ss.add(subject, '3')
     self.assertTrue(preExisting)
     self.assertEqual('3', subjectIndex)
Пример #8
0
 def testAddSubjectTwiceWithDifferentIndex(self):
     """
     Adding a subject to a SubjectStore and giving a subject index
     and then re-adding it with a different index must raise a
     SubjectStoreException.
     """
     subject = Subject(AARead('id', 'AA'))
     ss = SubjectStore()
     ss.add(subject, '3')
     error = ("^Already stored index \(3\) for subject 'id' does not match "
              "subsequently passed index \(4\) for the subject\.$")
     six.assertRaisesRegex(self, SubjectStoreException, error, ss.add,
                           subject, '4')
Пример #9
0
 def testSaveRestoreNonEmpty(self):
     """
     After a save/restore of a non-empty subject store, the subject store
     must be as expected.
     """
     ss = SubjectStore()
     subject = Subject(AARead('id', 'AA'), 6)
     ss.add(subject, '3')
     fp = StringIO()
     ss.save(fp)
     fp.seek(0)
     ss = SubjectStore.restore(fp)
     self.assertEqual(1, len(ss))
     self.assertEqual('3', ss.getIndexBySubject(subject))
     result = ss.getSubjectByIndex('3')
     self.assertEqual(subject, result)
     self.assertEqual(6, result.hashCount)
Пример #10
0
    def __init__(self,
                 dbParams,
                 _id=None,
                 subjectStore=None,
                 checksum=None,
                 disconnectedBackends=None,
                 filePrefix=None):
        self.dbParams = dbParams
        # Assign ourselves a random id to make backend name collisions
        # highly unlikely. I.e., if an unknown backend connects, the name
        # it supplies should be very unlikely to be accepted.
        self._id = _id or '%020d' % int(uniform(1, 1e20))
        self._subjectStore = subjectStore or SubjectStore()
        for method in ('getIndexBySubject', 'getSubjectByIndex',
                       'getSubjects'):
            setattr(self, method, getattr(self._subjectStore, method))
        # Our checksum will be based on our parameters. The checksum should
        # not be based on our id as that's a random value that changes from
        # run to run. If we used it in the checksum then if we restarted a
        # connector and it began to talk to existing backends, it would
        # have a different checksum and errors would result.
        self._checksum = checksum or Checksum(dbParams.checksum)
        # In self._disconnectedBackends and self._backends, keys are
        # backend names and values are Checksum instances.
        self._disconnectedBackends = disconnectedBackends or {}
        self._backends = {}
        self._filePrefix = filePrefix
        # _sessionIdToName maps ephemeral WAMP session ids to (connected)
        # backend names.
        self._sessionIdToName = {}
        # The WAMP server component. This will be set by the server
        # database component using our setComponent method.
        self._component = None

        # TODO: Remove.
        logging.info('Connector started. Disconnected backends: %r' %
                     self._disconnectedBackends)
Пример #11
0
 def testEmptyStoreHasZeroLength(self):
     """
     An empty SubjectStore must have zero length.
     """
     self.assertEqual(0, len(SubjectStore()))