def test_elastic_commit(self): """Test the auto_commit_interval attribute.""" doc = {'_id': '3', 'name': 'Waldo'} # test cases: # None = no autocommit # 0 = commit immediately # x > 0 = commit within x seconds for commit_interval in [None, 0, 2, 8]: docman = DocManager(elastic_pair, auto_commit_interval=commit_interval) docman.upsert(doc, *TESTARGS) if commit_interval: # Allow just a little extra time time.sleep(commit_interval + 2) results = list(self._search()) if commit_interval is None: self.assertEqual(len(results), 0, "should not commit document with " "auto_commit_interval = None") else: self.assertEqual(len(results), 1, "should commit document with " "auto_commit_interval = %s" % ( commit_interval,)) self.assertEqual(results[0]["name"], "Waldo") docman.stop() self._remove() retry_until_ok(self.elastic_conn.indices.refresh, index="")
def test_elastic_commit(self): """Test that documents get properly added to ElasticSearch. """ docc = {'_id': '3', 'name': 'Waldo', 'ns': 'test.test'} docman = DocManager(elastic_pair) # test cases: # -1 = no autocommit # 0 = commit immediately # x > 0 = commit within x seconds for autocommit_interval in [None, 0, 1, 2]: docman.auto_commit_interval = autocommit_interval docman.upsert(docc) if autocommit_interval is None: docman.commit() else: # Allow just a little extra time time.sleep(autocommit_interval + 1) results = list(self._search()) self.assertEqual( len(results), 1, "should commit document with " "auto_commit_interval = %s" % str(autocommit_interval)) self.assertEqual(results[0]["name"], "Waldo") self._remove() docman.stop()
def test_elastic_commit(self): """Test that documents get properly added to ElasticSearch. """ docc = {'_id': '3', 'name': 'Waldo', 'ns': 'test.test'} docman = DocManager(elastic_pair) # test cases: # -1 = no autocommit # 0 = commit immediately # x > 0 = commit within x seconds for autocommit_interval in [None, 0, 1, 2]: docman.auto_commit_interval = autocommit_interval docman.upsert(docc) if autocommit_interval is None: docman.commit() else: # Allow just a little extra time time.sleep(autocommit_interval + 1) results = list(self._search()) self.assertEqual(len(results), 1, "should commit document with " "auto_commit_interval = %s" % str( autocommit_interval)) self.assertEqual(results[0]["name"], "Waldo") self._remove() docman.stop()
def setUpClass(cls): """ Starts the cluster """ cls.elastic_doc = DocManager(elastic_pair, auto_commit=False) _, cls.secondary_p, cls.primary_p = start_replica_set('test-elastic') cls.conn = MongoClient(mongo_host, cls.primary_p, replicaSet='test-elastic')
def test_auto_send_interval(self): """Test the auto_send_interval auto_send_interval should control the amount of time to wait before sending (but not committing) buffered operations. """ doc = {'_id': '3', 'name': 'Waldo'} # test cases: # None, 0 = no auto send # x > 0 = send buffered operations within x seconds for send_interval in [None, 0, 3, 8]: docman = DocManager(elastic_pair, autoSendInterval=send_interval, auto_commit_interval=None) docman.upsert(doc, *TESTARGS) if send_interval: # Allow just a little extra time time.sleep(send_interval + 2) results = list(self._search()) self.assertEqual( len(results), 0, "documents should not be commited with " "auto_commit_interval=None and auto_commit_interval=%s" % ( send_interval,)) # Commit the possibly sent changes and search again retry_until_ok(self.elastic_conn.indices.refresh, index="") results = list(self._search()) if not send_interval: self.assertEqual( len(results), 0, "should not send document with auto_send_interval=%s" % ( send_interval,)) else: self.assertEqual( len(results), 1, "should send document with auto_send_interval=%s" % ( send_interval,)) self.assertEqual(results[0]["name"], "Waldo") docman.stop() self._remove() retry_until_ok(self.elastic_conn.indices.refresh, index="")
def test_invalid_url(self): """Ensure DocManager fails for a bad Solr url. """ #Invalid URL #Invalid URL count = 0 try: DocManager("http://doesntexist.cskjdfhskdjfhdsom") except SystemError: count += 1 self.assertTrue(count == 1)
def setUpClass(cls): """ Starts the cluster """ os.system('rm %s; touch %s' % (CONFIG, CONFIG)) cls.elastic_doc = DocManager('localhost:9200') cls.elastic_doc._remove() cls.flag = start_cluster() if cls.flag: cls.conn = Connection('%s:%s' % (HOSTNAME, PORTS_ONE['MONGOS']), replicaSet="demo-repl") import logging logger = logging.getLogger() loglevel = logging.INFO logger.setLevel(loglevel)
def setUp(self): """Start a new Connector for each test.""" super(TestElastic, self).setUp() try: os.unlink("oplog.timestamp") except OSError: pass docman = DocManager(elastic_pair) self.connector = Connector(mongo_address=self.repl_set.uri, ns_set=['test.test'], doc_managers=(docman, ), gridfs_set=['test.test']) self.conn.test.test.drop() self.conn.test.test.files.drop() self.conn.test.test.chunks.drop() self.connector.start() assert_soon(lambda: len(self.connector.shard_set) > 0) assert_soon(lambda: self._count() == 0)
def setUpClass(cls): cls.elastic_conn = Elasticsearch(hosts=[elastic_pair]) cls.elastic_doc = DocManager(elastic_pair, auto_commit_interval=0)
def setUpClass(cls): """Initializes ES DocManager and a direct connection to elastic_conn """ cls.elastic_doc = DocManager("http://localhost:9200", auto_commit=False) cls.elastic_conn = ES(server="http://localhost:9200")
def setUpClass(cls): """Initializes ES DocManager and a direct connection to elastic_conn """ cls.elastic_doc = DocManager("localhost:9200", auto_commit_interval=0) cls.elastic_conn = Elasticsearch(server="localhost:9200")