Selaa lähdekoodia

HUE-9100 [hive] Light style refactoring while browsing over the logic

Romain 5 vuotta sitten
vanhempi
commit
aa95e6e134

+ 5 - 4
apps/beeswax/src/beeswax/conf.py

@@ -333,12 +333,13 @@ def has_multiple_sessions():
 
 CLOSE_SESSIONS = Config(
   key="close_sessions",
-  help=_t('When set to True, Hue will close sessions created for background queries and open new ones as needed.'
-          'When set to False, Hue will keep sessions created for background queries opened and reuse them as needed.'
-          'This flag is useful when max_number_of_sessions != 1'),
+  help=_t(
+      'When set to True, Hue will close sessions created for background queries and open new ones as needed.'
+      'When set to False, Hue will keep sessions created for background queries opened and reuse them as needed.'
+      'This flag is useful when max_number_of_sessions != 1'),
   type=coerce_bool,
   dynamic_default=has_multiple_sessions
 )
 
 def has_session_pool():
-  return has_multiple_sessions() and not CLOSE_SESSIONS.get()
+  return has_multiple_sessions() and not CLOSE_SESSIONS.get()

+ 2 - 3
apps/beeswax/src/beeswax/models.py

@@ -415,8 +415,7 @@ class SessionManager(models.Manager):
     sessions = Session.objects.get_n_sessions(user, n=2 + n_sessions, application=application)
     LOG.debug('%s sessions found' % len(sessions))
     if sessions:
-      # Include trashed documents to keep the query lazy
-      # and avoid retrieving all documents
+      # Include trashed documents to keep the query lazy and avoid retrieving all documents
       docs = Document2.objects.get_history(doc_type='query-hive', user=user, include_trashed=True)
       busy_sessions = set()
 
@@ -431,7 +430,7 @@ class SessionManager(models.Manager):
         session_guid = snippet_data.get('result', {}).get('handle', {}).get('session_guid')
         status = snippet_data.get('status')
 
-        if status in [QueryHistory.STATE.submitted.name, QueryHistory.STATE.running.name]:
+        if status in (QueryHistory.STATE.submitted.name, QueryHistory.STATE.running.name):
           if session_guid is not None and session_guid not in busy_sessions:
             busy_sessions.add(session_guid)
 

+ 34 - 14
apps/beeswax/src/beeswax/server/hive_server2_lib_tests.py

@@ -354,10 +354,15 @@ class TestHiveServerTable():
       assert_equal(table.primary_keys[1].type, 'NULL')
       assert_equal(table.primary_keys[1].comment, 'NULL')
 
-class SessionTest():
+
+class TestSessionManagement():
+
   def test_call_session_single(self):
-    finish = (MAX_NUMBER_OF_SESSIONS.set_for_testing(1),
-                CLOSE_SESSIONS.set_for_testing(False))
+    finish = (
+        MAX_NUMBER_OF_SESSIONS.set_for_testing(1),
+        CLOSE_SESSIONS.set_for_testing(False)
+    )
+
     try:
       with patch('beeswax.server.hive_server2_lib.thrift_util.get_client') as get_client:
         with patch('beeswax.server.hive_server2_lib.HiveServerClient.open_session') as open_session:
@@ -386,8 +391,11 @@ class SessionTest():
         f()
 
   def test_call_session_pool(self):
-    finish = (MAX_NUMBER_OF_SESSIONS.set_for_testing(2),
-                CLOSE_SESSIONS.set_for_testing(False))
+    finish = (
+        MAX_NUMBER_OF_SESSIONS.set_for_testing(2),
+        CLOSE_SESSIONS.set_for_testing(False)
+    )
+
     try:
       with patch('beeswax.server.hive_server2_lib.thrift_util.get_client') as get_client:
         with patch('beeswax.server.hive_server2_lib.HiveServerClient.open_session') as open_session:
@@ -416,8 +424,11 @@ class SessionTest():
         f()
 
   def test_call_session_pool_limit(self):
-    finish = (MAX_NUMBER_OF_SESSIONS.set_for_testing(2),
-                CLOSE_SESSIONS.set_for_testing(False))
+    finish = (
+        MAX_NUMBER_OF_SESSIONS.set_for_testing(2),
+        CLOSE_SESSIONS.set_for_testing(False)
+    )
+
     try:
       with patch('beeswax.server.hive_server2_lib.thrift_util.get_client') as get_client:
         with patch('beeswax.server.hive_server2_lib.HiveServerClient.open_session') as open_session:
@@ -433,8 +444,11 @@ class SessionTest():
         f()
 
   def test_call_session_close_idle(self):
-    finish = (MAX_NUMBER_OF_SESSIONS.set_for_testing(-1),
-                CLOSE_SESSIONS.set_for_testing(True))
+    finish = (
+        MAX_NUMBER_OF_SESSIONS.set_for_testing(-1),
+        CLOSE_SESSIONS.set_for_testing(True)
+    )
+
     try:
       with patch('beeswax.server.hive_server2_lib.thrift_util.get_client') as get_client:
         with patch('beeswax.server.hive_server2_lib.HiveServerClient.open_session') as open_session:
@@ -461,8 +475,11 @@ class SessionTest():
         f()
 
   def test_call_session_close_idle_managed_queries(self):
-    finish = (MAX_NUMBER_OF_SESSIONS.set_for_testing(-1),
-                CLOSE_SESSIONS.set_for_testing(True))
+    finish = (
+        MAX_NUMBER_OF_SESSIONS.set_for_testing(-1),
+        CLOSE_SESSIONS.set_for_testing(True)
+    )
+
     try:
       with patch('beeswax.server.hive_server2_lib.thrift_util.get_client') as get_client:
         with patch('beeswax.server.hive_server2_lib.HiveServerClient.open_session') as open_session:
@@ -507,8 +524,11 @@ class SessionTest():
         f()
 
   def test_call_session_close_idle_limit(self):
-    finish = (MAX_NUMBER_OF_SESSIONS.set_for_testing(2),
-                CLOSE_SESSIONS.set_for_testing(True))
+    finish = (
+        MAX_NUMBER_OF_SESSIONS.set_for_testing(2),
+        CLOSE_SESSIONS.set_for_testing(True)
+    )
+
     try:
       with patch('beeswax.server.hive_server2_lib.thrift_util.get_client') as get_client:
         with patch('beeswax.server.hive_server2_lib.HiveServerClient.open_session') as open_session:
@@ -525,4 +545,4 @@ class SessionTest():
             open_session.assert_called_once()
     finally:
       for f in finish:
-        f()
+        f()