public async Task Attach() { var channel = TestHelper.CreateChannel(); var controller = new Controller.ControllerClient(channel); var request = new CreateVolumeRequest { Name = namingProvider.VolumeName(), }; populateSecretsFromEnv(request.ControllerCreateSecrets); var response = await controller.CreateVolumeAsync(request, null); Assert.NotNull(response.Volume); Assert.NotNull(response.Volume.Id); var volId = response.Volume.Id; var node = new Node.NodeClient(TestHelper.CreateChannel()); var tmppath = Path.Combine(Path.GetTempPath(), namingProvider.DirName()); try { var npr = new NodePublishVolumeRequest { VolumeId = volId, TargetPath = tmppath, }; populateSecretsFromEnv(npr.NodePublishSecrets); await node.NodePublishVolumeAsync(npr, null); var tmpfile = Path.Combine(tmppath, namingProvider.FileName()); var content = DateTimeOffset.UtcNow.ToString(); await File.AppendAllTextAsync(tmpfile, content); // TODO valid content through storage API, and enable DeleteVolumeAsync } finally { await node.NodeUnpublishVolumeAsync(new NodeUnpublishVolumeRequest { VolumeId = volId, TargetPath = tmppath, }, null); /* * await controller.DeleteVolumeAsync(new DeleteVolumeRequest * { * VolumeId = volId, * }); */ } }
public Task <ConnectResponse> ConnectAsync() { CancellationToken token; lock (Sync) { _cts?.Cancel(); _cts = new CancellationTokenSource(); token = _cts.Token; var channel = new Channel(_serverAddress, ChannelCredentials.Insecure); var client = new Node.NodeClient(channel); _loop = client.MessageLoop(); } Task.Factory.StartNew( async() => { while (!token.IsCancellationRequested) { var hasNewMsg = await _loop.ResponseStream.MoveNext(CancellationToken.None); if (!hasNewMsg) { break; } var msg = _loop.ResponseStream.Current; if (_internalSubscriber.TryGetValue(msg.GetId(), out var action)) { action(msg); } var onOnServerResponse = OnServerResponse; onOnServerResponse?.Invoke(msg); } }, TaskCreationOptions.LongRunning); return(SayHi()); }
public void Add(Node.NodeClient nodeClient) { this.nodeClients.Add(nodeClient); }