def test_redis_factory_with_without_master_service(self):
        config = {
            'redisDb': 0,
            'redisPrefix': 'test',
            'redisSentinels': [('test', 1234)],
            'redisSocketTimeout': 3
        }

        with self.assertRaises(SentinelConfigurationException):
            get_factory('abc', config=config)
    def test_redis_factory_with_wrong_data_in_sentinels_array(self):
        config = {
            'redisDb': 0,
            'redisPrefix': 'test',
            'redisSentinels': ['asdasd'],
            'redisMasterService': 'mymaster',
            'redisSocketTimeout': 3
        }

        with self.assertRaises(SentinelConfigurationException):
            get_factory('abc', config=config)
Beispiel #3
0
    def setUp(self):
        self._some_config = mock.MagicMock()
        self._split_changes_file_name = join(dirname(__file__),
                                             'splitGetTreatments.json')

        with open(self._split_changes_file_name) as f:
            self._json = load(f)
            split_definition = self._json['splits'][0]
            split_name = split_definition['name']

        self._redis = get_redis({'redisPrefix': 'getTreatmentsTest'})

        self._redis_split_cache = RedisSplitCache(self._redis)
        self._redis_split_cache.add_split(split_name, split_definition)
        self._client = Client(RedisBroker(self._redis, self._some_config))

        self._config = {
            'ready': 180000,
            'redisDb': 0,
            'redisHost': 'localhost',
            'redisPosrt': 6379,
            'redisPrefix': 'getTreatmentsTest'
        }
        self._factory = get_factory('asdqwe123456', config=self._config)
        self._split = self._factory.client()
Beispiel #4
0
    def test_client_without_impression_listener(self):
        config = {
            'ready': 180000,
            'redisDb': 0,
            'redisHost': 'localhost',
            'redisPosrt': 6379,
            'redisPrefix': 'customImpressionListenerTest'
        }
        factory = get_factory('asdqwe123456', config=config)
        split = factory.client()

        self.assertEqual(split.get_treatment('valid', 'iltest'), 'on')
        self.assertEqual(split.get_treatment('invalid', 'iltest'), 'off')
        self.assertEqual(split.get_treatment('valid', 'iltest_invalid'),
                         'control')
Beispiel #5
0
    def test_client_throwing_exception_in_listener(self):
        impressionListenerClient = ImpressionListenerClientWithException()

        config = {
            'ready': 180000,
            'impressionListener': impressionListenerClient,
            'redisDb': 0,
            'redisHost': 'localhost',
            'redisPosrt': 6379,
            'redisPrefix': 'customImpressionListenerTest'
        }
        factory = get_factory('asdqwe123456', config=config)
        split = factory.client()

        self.assertEqual(split.get_treatment('valid', 'iltest'), 'on')
Beispiel #6
0
 def __init__(self, sdk_token):
     super(BatchClient, self).__init__()
     try:
         self.factory = get_factory(sdk_token,
                                    config={
                                        "connectionTimeout":
                                        connection_timeout,
                                        "impressionsQueueSize": queue_size,
                                        "eventsQueueSize": queue_size,
                                        "eventsBulkSize": bulk_size,
                                        "impressionsBulkSize": bulk_size,
                                        "impressionsMode": "optimized"
                                    })
         self.factory.block_until_ready(20)
     except TimeoutException:
         menu.error_message("SDK failed to initialize")
         sys.exit(1)
     self.split_client = self.factory.client()
Beispiel #7
0
from splitio.exceptions import TimeoutException
from splitio import get_factory
from flask import Flask, render_template
import logging
logging.getLogger('splitio').setLevel(logging.DEBUG)
app = Flask(__name__)

factory = get_factory('6go42qijm6c548p47q4sjbrv756mvbbpej19',
                      sdk_api_base_url='https://sdk.split-stage.io/api',
                      events_api_base_url='https://events.split-stage.io/api',
                      auth_api_base_url='https://auth.split-stage.io/api')
try:
    factory.block_until_ready(5)  # wait up to 5 seconds
except TimeoutException:
    # Now the user can choose whether to abort the whole execution, or just keep going
    # without a ready client, which if configured properly, should become ready at some point.
    pass


@app.route("/")
def index():
    client = factory.client()
    treatment = client.get_treatment('*****@*****.**', 'the_queens_gambit_menu')
    if treatment == 'on':
        return render_template('index.html')
    else:
        return render_template('error.html')


@app.route("/lunch")
def lunch():