Rename sql backend object
This commit is contained in:
parent
5004712360
commit
7b3cf46732
@ -14,7 +14,7 @@ from .base import Backend
|
||||
logg = logging.getLogger().getChild(__name__)
|
||||
|
||||
|
||||
class SyncerBackend(Backend):
|
||||
class SQLBackend(Backend):
|
||||
"""Interface to block and transaction sync state.
|
||||
|
||||
:param chain_spec: Chain spec for the chain that syncer is running for.
|
||||
@ -23,7 +23,7 @@ class SyncerBackend(Backend):
|
||||
:type object_id: number
|
||||
"""
|
||||
def __init__(self, chain_spec, object_id):
|
||||
super(SyncerBackend, self).__init__()
|
||||
super(SQLBackend, self).__init__()
|
||||
self.db_session = None
|
||||
self.db_object = None
|
||||
self.db_object_filter = None
|
||||
@ -146,7 +146,7 @@ class SyncerBackend(Backend):
|
||||
object_id = BlockchainSync.first(str(chain_spec))
|
||||
if object_id == None:
|
||||
return None
|
||||
return SyncerBackend(chain_spec, object_id)
|
||||
return SQLBackend(chain_spec, object_id)
|
||||
|
||||
|
||||
|
||||
@ -176,7 +176,7 @@ class SyncerBackend(Backend):
|
||||
|
||||
session.close()
|
||||
|
||||
return SyncerBackend(chain_spec, object_id)
|
||||
return SQLBackend(chain_spec, object_id)
|
||||
|
||||
|
||||
@staticmethod
|
||||
@ -209,7 +209,7 @@ class SyncerBackend(Backend):
|
||||
session.close()
|
||||
|
||||
for object_id in object_ids:
|
||||
s = SyncerBackend(chain_spec, object_id)
|
||||
s = SQLBackend(chain_spec, object_id)
|
||||
logg.debug('resume unfinished {}'.format(s))
|
||||
syncers.append(s)
|
||||
|
||||
@ -243,7 +243,7 @@ class SyncerBackend(Backend):
|
||||
session.add(of)
|
||||
session.commit()
|
||||
|
||||
backend = SyncerBackend(chain_spec, object_id)
|
||||
backend = SQLBackend(chain_spec, object_id)
|
||||
syncers.append(backend)
|
||||
|
||||
logg.debug('last live session resume {}'.format(backend))
|
||||
@ -278,7 +278,7 @@ class SyncerBackend(Backend):
|
||||
|
||||
session.close()
|
||||
|
||||
return SyncerBackend(chain_spec, object_id)
|
||||
return SQLBackend(chain_spec, object_id)
|
||||
|
||||
|
||||
def register_filter(self, name):
|
||||
|
@ -8,7 +8,7 @@ from chainlib.chain import ChainSpec
|
||||
# local imports
|
||||
from chainsyncer.db.models.base import SessionBase
|
||||
from chainsyncer.db.models.filter import BlockchainSyncFilter
|
||||
from chainsyncer.backend.sql import SyncerBackend
|
||||
from chainsyncer.backend.sql import SQLBackend
|
||||
|
||||
# testutil imports
|
||||
from tests.base import TestBase
|
||||
@ -20,19 +20,19 @@ class TestDatabase(TestBase):
|
||||
|
||||
|
||||
def test_backend_live(self):
|
||||
s = SyncerBackend.live(self.chain_spec, 42)
|
||||
s = SQLBackend.live(self.chain_spec, 42)
|
||||
self.assertEqual(s.object_id, 1)
|
||||
backend = SyncerBackend.first(self.chain_spec)
|
||||
#SyncerBackend(self.chain_spec, sync_id)
|
||||
backend = SQLBackend.first(self.chain_spec)
|
||||
#SQLBackend(self.chain_spec, sync_id)
|
||||
self.assertEqual(backend.object_id, 1)
|
||||
|
||||
bogus_chain_spec = ChainSpec('bogus', 'foo', 13, 'baz')
|
||||
sync_id = SyncerBackend.first(bogus_chain_spec)
|
||||
sync_id = SQLBackend.first(bogus_chain_spec)
|
||||
self.assertIsNone(sync_id)
|
||||
|
||||
|
||||
def test_backend_filter(self):
|
||||
s = SyncerBackend.live(self.chain_spec, 42)
|
||||
s = SQLBackend.live(self.chain_spec, 42)
|
||||
|
||||
s.connect()
|
||||
filter_id = s.db_object_filter.id
|
||||
@ -69,40 +69,40 @@ class TestDatabase(TestBase):
|
||||
|
||||
|
||||
def test_backend_retrieve(self):
|
||||
s = SyncerBackend.live(self.chain_spec, 42)
|
||||
s = SQLBackend.live(self.chain_spec, 42)
|
||||
s.register_filter('foo')
|
||||
s.register_filter('bar')
|
||||
s.register_filter('baz')
|
||||
|
||||
s.set(42, 13)
|
||||
|
||||
s = SyncerBackend.first(self.chain_spec)
|
||||
s = SQLBackend.first(self.chain_spec)
|
||||
self.assertEqual(s.get(), ((42,13), 0))
|
||||
|
||||
|
||||
def test_backend_initial(self):
|
||||
with self.assertRaises(ValueError):
|
||||
s = SyncerBackend.initial(self.chain_spec, 42, 42)
|
||||
s = SQLBackend.initial(self.chain_spec, 42, 42)
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
s = SyncerBackend.initial(self.chain_spec, 42, 43)
|
||||
s = SQLBackend.initial(self.chain_spec, 42, 43)
|
||||
|
||||
s = SyncerBackend.initial(self.chain_spec, 42, 13)
|
||||
s = SQLBackend.initial(self.chain_spec, 42, 13)
|
||||
|
||||
s.set(43, 13)
|
||||
|
||||
s = SyncerBackend.first(self.chain_spec)
|
||||
s = SQLBackend.first(self.chain_spec)
|
||||
self.assertEqual(s.get(), ((43,13), 0))
|
||||
self.assertEqual(s.start(), ((13,0), 0))
|
||||
|
||||
|
||||
def test_backend_resume(self):
|
||||
s = SyncerBackend.resume(self.chain_spec, 666)
|
||||
s = SQLBackend.resume(self.chain_spec, 666)
|
||||
self.assertEqual(len(s), 0)
|
||||
|
||||
s = SyncerBackend.live(self.chain_spec, 42)
|
||||
s = SQLBackend.live(self.chain_spec, 42)
|
||||
original_id = s.object_id
|
||||
s = SyncerBackend.resume(self.chain_spec, 666)
|
||||
s = SQLBackend.resume(self.chain_spec, 666)
|
||||
self.assertEqual(len(s), 1)
|
||||
resumed_id = s[0].object_id
|
||||
self.assertEqual(resumed_id, original_id + 1)
|
||||
@ -110,25 +110,25 @@ class TestDatabase(TestBase):
|
||||
|
||||
|
||||
def test_backend_resume_when_completed(self):
|
||||
s = SyncerBackend.live(self.chain_spec, 42)
|
||||
s = SQLBackend.live(self.chain_spec, 42)
|
||||
|
||||
s = SyncerBackend.resume(self.chain_spec, 666)
|
||||
s = SQLBackend.resume(self.chain_spec, 666)
|
||||
s[0].set(666, 0)
|
||||
|
||||
s = SyncerBackend.resume(self.chain_spec, 666)
|
||||
s = SQLBackend.resume(self.chain_spec, 666)
|
||||
self.assertEqual(len(s), 0)
|
||||
|
||||
|
||||
def test_backend_resume_several(self):
|
||||
s = SyncerBackend.live(self.chain_spec, 42)
|
||||
s = SQLBackend.live(self.chain_spec, 42)
|
||||
s.set(43, 13)
|
||||
|
||||
s = SyncerBackend.resume(self.chain_spec, 666)
|
||||
SyncerBackend.live(self.chain_spec, 666)
|
||||
s = SQLBackend.resume(self.chain_spec, 666)
|
||||
SQLBackend.live(self.chain_spec, 666)
|
||||
s[0].set(123, 2)
|
||||
|
||||
s = SyncerBackend.resume(self.chain_spec, 1024)
|
||||
SyncerBackend.live(self.chain_spec, 1024)
|
||||
s = SQLBackend.resume(self.chain_spec, 1024)
|
||||
SQLBackend.live(self.chain_spec, 1024)
|
||||
|
||||
self.assertEqual(len(s), 2)
|
||||
self.assertEqual(s[0].target(), (666, 0))
|
||||
@ -138,7 +138,7 @@ class TestDatabase(TestBase):
|
||||
|
||||
|
||||
def test_backend_resume_filter(self):
|
||||
s = SyncerBackend.live(self.chain_spec, 42)
|
||||
s = SQLBackend.live(self.chain_spec, 42)
|
||||
s.register_filter('foo')
|
||||
s.register_filter('bar')
|
||||
s.register_filter('baz')
|
||||
@ -147,7 +147,7 @@ class TestDatabase(TestBase):
|
||||
s.complete_filter(0)
|
||||
s.complete_filter(2)
|
||||
|
||||
s = SyncerBackend.resume(self.chain_spec, 666)
|
||||
s = SQLBackend.resume(self.chain_spec, 666)
|
||||
(pair, flags) = s[0].get()
|
||||
|
||||
self.assertEqual(flags, 5)
|
||||
|
@ -9,7 +9,7 @@ from chainlib.chain import ChainSpec
|
||||
|
||||
# local imports
|
||||
from chainsyncer.backend.memory import MemBackend
|
||||
from chainsyncer.backend.sql import SyncerBackend
|
||||
from chainsyncer.backend.sql import SQLBackend
|
||||
from chainsyncer.backend.file import (
|
||||
FileBackend,
|
||||
data_dir_for,
|
||||
@ -128,7 +128,7 @@ class TestInterrupt(TestBase):
|
||||
|
||||
def test_filter_interrupt_sql(self):
|
||||
for vector in self.vectors:
|
||||
self.backend = SyncerBackend.initial(self.chain_spec, len(vector))
|
||||
self.backend = SQLBackend.initial(self.chain_spec, len(vector))
|
||||
self.assert_filter_interrupt(vector)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user