This repository has been archived by the owner on Oct 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#59 Handle network problems, allow to correctly reinitialise after it
- Loading branch information
Showing
5 changed files
with
108 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,48 @@ | ||
import unittest | ||
from unittest.mock import MagicMock | ||
from bubuku.zookeeper.exhibitor import AWSExhibitorAddressProvider | ||
|
||
from bubuku.zookeeper.exhibitor import ExhibitorAddressProvider | ||
|
||
def test_get_latest_address(): | ||
AWSExhibitorAddressProvider.get_addresses_by_lb_name = MagicMock(return_value=['aws-lb-1', 'aws-lb-2']) | ||
AWSExhibitorAddressProvider._query_exhibitors = MagicMock(return_value={'servers':['aws-lb-1-new'], 'port': 99}) | ||
|
||
address_provider = AWSExhibitorAddressProvider('zk-stack-name', 'eu-west') | ||
actual_result = address_provider.get_latest_address() | ||
class ExhibitorAddressProviderTest(unittest.TestCase): | ||
def test_get_latest_address(self): | ||
address_provider = ExhibitorAddressProvider(lambda: ['aws-lb-1', 'aws-lb-2']) | ||
address_provider._query_exhibitors = lambda _: {'servers': ['aws-lb-1-new'], 'port': 99} | ||
|
||
assert actual_result == (['aws-lb-1-new'], 99) | ||
actual_result = address_provider.get_latest_address() | ||
|
||
assert actual_result == (['aws-lb-1-new'], 99) | ||
|
||
def test_get_latest_address_no_exhibitors(): | ||
AWSExhibitorAddressProvider.get_addresses_by_lb_name = MagicMock(return_value=['aws-lb-1', 'aws-lb-2']) | ||
AWSExhibitorAddressProvider._query_exhibitors = MagicMock(return_value=None) | ||
def test_get_latest_address_no_exhibitors(self): | ||
address_provider = ExhibitorAddressProvider(lambda: ['aws-lb-1', 'aws-lb-2']) | ||
address_provider._query_exhibitors = lambda _: None | ||
|
||
address_provider = AWSExhibitorAddressProvider('zk-stack-name', 'eu-west') | ||
actual_result = address_provider.get_latest_address() | ||
actual_result = address_provider.get_latest_address() | ||
assert actual_result is None | ||
|
||
assert actual_result is None | ||
def test_get_latest_address_2(self): | ||
address_provider = ExhibitorAddressProvider(lambda: ['aws-lb-1', 'aws-lb-2']) | ||
address_provider._query_exhibitors = MagicMock() | ||
address_provider._query_exhibitors.side_effect = [None, {'servers': ['aws-lb-1-new'], 'port': 99}] | ||
|
||
actual_result = address_provider.get_latest_address() | ||
|
||
def test_get_latest_address_2(): | ||
AWSExhibitorAddressProvider.get_addresses_by_lb_name = MagicMock(return_value=['aws-lb-1', 'aws-lb-2']) | ||
AWSExhibitorAddressProvider._query_exhibitors = MagicMock() | ||
AWSExhibitorAddressProvider._query_exhibitors.side_effect = [None, {'servers':['aws-lb-1-new'], 'port': 99}] | ||
assert address_provider._query_exhibitors.call_count == 2 | ||
assert actual_result == (['aws-lb-1-new'], 99) | ||
|
||
address_provider = AWSExhibitorAddressProvider('zk-stack-name', 'eu-west') | ||
actual_result = address_provider.get_latest_address() | ||
def test_addresses_are_sorted(self): | ||
address_provider = ExhibitorAddressProvider(lambda: ['aws-lb-1', 'aws-lb-2']) | ||
address_provider._query_exhibitors = lambda _: {'servers': ['1', '2', '3'], 'port': '1234'} | ||
tmp_result = address_provider.get_latest_address() | ||
|
||
# Check that two calls in sequence will return the same value | ||
assert tmp_result == address_provider.get_latest_address() | ||
|
||
# Check sort 1 | ||
address_provider._query_exhibitors = lambda _: {'servers': ['2', '1', '3'], 'port': '1234'} | ||
assert tmp_result == address_provider.get_latest_address() | ||
|
||
# Check sort again (just to be sure) | ||
address_provider._query_exhibitors = lambda _: {'servers': ['3', '2', '1'], 'port': '1234'} | ||
assert tmp_result == address_provider.get_latest_address() | ||
|
||
assert AWSExhibitorAddressProvider._query_exhibitors.call_count == 2 | ||
assert actual_result == (['aws-lb-1-new'], 99) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters