async def sharedClient(): port = random.randint(1000, 9000) client = makeClient(port=port) port = client.port redisServerTask = asyncio.ensure_future(runRedisServer(port)) await asyncio.sleep(0.1) # wait a bit until the server is running await client.send('DEL', 'a') val = await client.send('INCR', 'a') async def incrementer(client, count): for i in range(count): await client.send('INCR', 'a') if False: # wait a random amount of time, a tenth of a millisecond waitTime = random.randint(1, 8) / 10000 await asyncio.sleep(waitTime) start = time.time() taskA = asyncio.ensure_future(incrementer(client, 1000)) taskB = asyncio.ensure_future(incrementer(client, 1000)) taskC = asyncio.ensure_future(incrementer(client, 1000)) taskD = asyncio.ensure_future(incrementer(client, 1000)) taskE = asyncio.ensure_future(incrementer(client, 1000)) await taskA await taskB await taskC await taskD await taskE delta = time.time() - start print(delta) val = await client.send('GET', 'a') assert val == b'5001' # Now cancel the server and wait a bit (do we need this ?) redisServerTask.cancel() await redisServerTask await asyncio.sleep(0.1) # wait a bit until the server is not running with pytest.raises(Exception): await client.send('PING') assert not client.connected()
async def coro(): root = tempfile.mkdtemp() clusterReadyFile = os.path.join(root, 'redis_cluster_ready.json') startPort = 0 redisUrl = f'redis://localhost:{startPort}' size = 3 # redisPassword = '******' redisPassword = None redisUser = '' replicas = 1 manual = True runClusterTask = asyncio.ensure_future( runNewCluster( root, clusterReadyFile, startPort, size, redisPassword, redisUser, replicas, manual, )) # Wait until cluster is initialized while not os.path.exists(clusterReadyFile): await asyncio.sleep(0.1) with open(clusterReadyFile) as f: data = json.loads(f.read()) startPort = data['start_port'] redisUrl = f'redis://localhost:{startPort}' client = makeClient(startPort, redisPassword, redisUser) await checkStrings(client) # now analyze keyspace for 3 seconds task = asyncio.ensure_future( analyzeKeyspace(redisUrl, redisPassword, redisUser, 3)) # wait a tiny bit so that the analyzer is ready # (it needs to make a couple of pubsub subscriptions) await asyncio.sleep(0.1) # Write once for i in range(100): for j in range(i): key = f'channel_{i}' value = f'val_{i}' result = await client.send('SET', key, value) assert result # Validate that we can read back what we wrote for i in range(1, 100): key = f'channel_{i}' value = f'val_{i}' val = await client.send('GET', key) val = val.decode() assert val == value await task keySpace = task.result() weights = keySpace.keys print('weights', weights) signature, balanced, fullCoverage = await getClusterSignature( redisUrl, redisPassword, redisUser) assert balanced assert fullCoverage ret = await binPackingReshardCoroutine(redisUrl, redisPassword, redisUser, weights, timeout=15) assert ret newSignature, balanced, fullCoverage = await getClusterSignature( redisUrl, redisPassword, redisUser) assert signature != newSignature assert balanced assert fullCoverage # Now run cluster check await runRedisCliClusterCheck(startPort, redisPassword, redisUser) # Validate that we can read back what we wrote, after resharding for i in range(1, 100): key = f'channel_{i}' value = f'val_{i}' val = await client.send('GET', key) val = val.decode() assert val == value # Do another reshard. This one should be a no-op # This should return statistics about the resharding ret = await binPackingReshardCoroutine(redisUrl, redisPassword, redisUrl, weights, timeout=20) assert ret task.cancel() await task runClusterTask.cancel() await runClusterTask
def client(): cli = makeClient() yield cli
def client(): port = random.randint(1000, 9000) cli = makeClient(port=port) yield cli
async def coro(): root = tempfile.mkdtemp() clusterReadyFile = os.path.join(root, 'redis_cluster_ready.json') startPort = 0 redisPassword = '******' redisUser = None replicas = 1 manual = True serverVersion = getRedisServerMajorVersion() if serverVersion >= 6: redisUser = '******' size = 3 task = asyncio.ensure_future( runNewCluster( root, clusterReadyFile, startPort, size, redisPassword, redisUser, replicas, manual, ) ) # Wait until cluster is initialized while not os.path.exists(clusterReadyFile): await asyncio.sleep(0.1) with open(clusterReadyFile) as f: data = json.loads(f.read()) startPort = data['start_port'] redisUrl = f'redis://localhost:{startPort}' client = makeClient(startPort, redisPassword, redisUser) # Write something in redis key = 'channel_2' value = 'val_2' res = await client.send('SET', key, value) assert res is not None # Validate that we can read back what we wrote earlier results = await client.send('GET', key) val = results.decode() assert val == value signature, balanced, fullCoverage = await getClusterSignature( redisUrl, redisPassword, redisUser ) assert balanced assert fullCoverage # ret = await binPackingReshardCoroutine(redisUrl, weights, timeout=15) # assert ret slot = 1978 nodes = await client.cluster_nodes() masterNodes = [node for node in nodes if node.role == 'master'] masterClients = [ makeClientfromNode(node, redisPassword, redisUser) for node in masterNodes ] sourceNode = masterNodes[0] destinationNode = masterNodes[1] await migrateSlot( masterClients, redisPassword, redisUser, slot, sourceNode, destinationNode, dry=False, ) consistent = await waitForClusterViewToBeConsistent( redisUrl, redisPassword, redisUser, timeout=5 ) assert consistent newSignature, balanced, fullCoverage = await getClusterSignature( redisUrl, redisPassword, redisUser ) assert signature != newSignature assert balanced assert fullCoverage # Now run cluster check await runRedisCliClusterCheck(startPort, redisPassword, redisUser) # Validate that we can read back what we wrote, after resharding results = await client.send('GET', key) val = results.decode() assert val == value task.cancel() await task
async def coro(): root = tempfile.mkdtemp() clusterReadyFile = os.path.join(root, 'redis_cluster_ready.json') startPort = 0 size = 3 redisPassword = '******' redisUser = None replicas = 1 manual = True serverVersion = getRedisServerMajorVersion() if serverVersion >= 6: redisUser = '******' task = asyncio.ensure_future( runNewCluster( root, clusterReadyFile, startPort, size, redisPassword, redisUser, replicas, manual, ) ) # Wait until cluster is initialized while not os.path.exists(clusterReadyFile): await asyncio.sleep(0.1) with open(clusterReadyFile) as f: data = json.loads(f.read()) startPort = data['start_port'] redisUrl = f'redis://localhost:{startPort}' client = makeClient(startPort, redisPassword, redisUser) # Write once for i in range(100): for j in range(i): key = f'channel_{i}' value = f'val_{i}' result = await client.send('SET', key, value) assert result # Validate that we can read back what we wrote for i in range(1, 100): key = f'channel_{i}' value = f'val_{i}' val = await client.send('GET', key) val = val.decode() assert val == value signature, balanced, fullCoverage = await getClusterSignature( redisUrl, redisPassword, redisUser ) assert balanced assert fullCoverage # Move slots from the first to the second node nodes = await client.cluster_nodes() sourceNodeId = nodes[0].node_id targetNodeId = nodes[1].node_id slots = 500 ret = await moveSlotsReshardCoroutine( redisUrl, redisPassword, redisUser, sourceNodeId, targetNodeId, slots, timeout=15, dry=False, ) assert ret newSignature, balanced, fullCoverage = await getClusterSignature( redisUrl, redisPassword, redisUser ) assert signature != newSignature assert balanced assert fullCoverage # Now run cluster check await runRedisCliClusterCheck(startPort, redisPassword, redisUser) # Validate that we can read back what we wrote, after resharding for i in range(1, 100): key = f'channel_{i}' value = f'val_{i}' val = await client.send('GET', key) val = val.decode() assert val == value # Do another reshard. ret = await moveSlotsReshardCoroutine( redisUrl, redisPassword, redisUser, sourceNodeId, targetNodeId, slots, timeout=15, dry=False, ) assert ret newSignature, balanced, fullCoverage = await getClusterSignature( redisUrl, redisPassword, redisUser ) assert signature != newSignature assert balanced assert fullCoverage # Validate that we can read back what we wrote, after resharding for i in range(1, 100): key = f'channel_{i}' value = f'val_{i}' val = await client.send('GET', key) val = val.decode() assert val == value task.cancel() await task