|
1 | 1 | using Grpc.Core; |
2 | 2 | using Moq; |
3 | 3 | using Xunit; |
| 4 | +using Xunit.Sdk; |
4 | 5 | using Ydb.Issue; |
5 | 6 | using Ydb.Query; |
6 | 7 | using Ydb.Query.V1; |
@@ -182,6 +183,89 @@ public async Task Open_WhenSuccessOpenThenAttachStreamSendBadSession_IsNotBroken |
182 | 183 | Assert.True(session.IsBroken); |
183 | 184 | } |
184 | 185 |
|
| 186 | + [Fact] |
| 187 | + public async Task Delete_WhenSuccessOpenSession_IsBroken() |
| 188 | + { |
| 189 | + SetupSuccessCreateSession(); |
| 190 | + var tcsSecondMoveAttachStream = SetupAttachStream(); |
| 191 | + var session = _poolingSessionFactory.NewSession(_poolingSessionSource); |
| 192 | + await session.Open(CancellationToken.None); |
| 193 | + _mockIDriver.Setup(driver => driver.UnaryCall( |
| 194 | + QueryService.DeleteSessionMethod, |
| 195 | + It.Is<DeleteSessionRequest>(request => request.SessionId.Equals(SessionId)), |
| 196 | + It.Is<GrpcRequestSettings>(grpcRequestSettings => grpcRequestSettings.NodeId == NodeId)) |
| 197 | + ); |
| 198 | + Assert.False(session.IsBroken); |
| 199 | + await session.DeleteSession(); |
| 200 | + Assert.True(session.IsBroken); |
| 201 | + _mockIDriver.Verify(driver => driver.UnaryCall(QueryService.DeleteSessionMethod, |
| 202 | + It.IsAny<DeleteSessionRequest>(), It.IsAny<GrpcRequestSettings>())); |
| 203 | + tcsSecondMoveAttachStream.TrySetResult(false); |
| 204 | + } |
| 205 | + |
| 206 | + [Fact] |
| 207 | + public async Task Delete_WhenSuccessOpenSessionBadSessionInAttachStream_IsBroken() |
| 208 | + { |
| 209 | + SetupSuccessCreateSession(); |
| 210 | + var tcsSecondMoveAttachStream = SetupAttachStream(); |
| 211 | + var session = _poolingSessionFactory.NewSession(_poolingSessionSource); |
| 212 | + await session.Open(CancellationToken.None); |
| 213 | + _mockIDriver.Setup(driver => driver.UnaryCall( |
| 214 | + QueryService.DeleteSessionMethod, |
| 215 | + It.Is<DeleteSessionRequest>(request => request.SessionId.Equals(SessionId)), |
| 216 | + It.Is<GrpcRequestSettings>(grpcRequestSettings => grpcRequestSettings.NodeId == NodeId)) |
| 217 | + ); |
| 218 | + Assert.False(session.IsBroken); |
| 219 | + session.OnNotSuccessStatusCode(StatusCode.BadSession); |
| 220 | + await session.DeleteSession(); |
| 221 | + Assert.True(session.IsBroken); |
| 222 | + _mockIDriver.Verify(driver => driver.UnaryCall(QueryService.DeleteSessionMethod, |
| 223 | + It.IsAny<DeleteSessionRequest>(), It.IsAny<GrpcRequestSettings>()), Times.Never); |
| 224 | + tcsSecondMoveAttachStream.TrySetResult(false); |
| 225 | + } |
| 226 | + |
| 227 | + [Fact] |
| 228 | + public async Task CommitTransaction_WhenSuccessOpenSession_AssertNodeId_SessionId_YdbException() |
| 229 | + { |
| 230 | + const string txId = "txId"; |
| 231 | + SetupSuccessCreateSession(); |
| 232 | + var tcsSecondMoveAttachStream = SetupAttachStream(); |
| 233 | + var session = _poolingSessionFactory.NewSession(_poolingSessionSource); |
| 234 | + await session.Open(CancellationToken.None); |
| 235 | + _mockIDriver.Setup(driver => driver.UnaryCall( |
| 236 | + QueryService.CommitTransactionMethod, |
| 237 | + It.Is<CommitTransactionRequest>(request => |
| 238 | + request.SessionId.Equals(SessionId) && request.TxId.Equals(txId)), |
| 239 | + It.Is<GrpcRequestSettings>(grpcRequestSettings => grpcRequestSettings.NodeId == NodeId)) |
| 240 | + ).ThrowsAsync(YdbException.FromServer(StatusIds.Types.StatusCode.Aborted, [])); |
| 241 | + Assert.False(session.IsBroken); |
| 242 | + var ydbException = await Assert.ThrowsAsync<YdbException>(() => session.CommitTransaction(txId)); |
| 243 | + Assert.Equal(StatusCode.Aborted, ydbException.Code); |
| 244 | + Assert.Equal("Status: Aborted", ydbException.Message); |
| 245 | + tcsSecondMoveAttachStream.TrySetResult(true); |
| 246 | + } |
| 247 | + |
| 248 | + [Fact] |
| 249 | + public async Task RollbackTransaction_WhenSuccessOpenSession_AssertNodeId_SessionId_YdbException() |
| 250 | + { |
| 251 | + const string txId = "txId"; |
| 252 | + SetupSuccessCreateSession(); |
| 253 | + var tcsSecondMoveAttachStream = SetupAttachStream(); |
| 254 | + var session = _poolingSessionFactory.NewSession(_poolingSessionSource); |
| 255 | + await session.Open(CancellationToken.None); |
| 256 | + _mockIDriver.Setup(driver => driver.UnaryCall( |
| 257 | + QueryService.RollbackTransactionMethod, |
| 258 | + It.Is<RollbackTransactionRequest>(request => |
| 259 | + request.SessionId.Equals(SessionId) && request.TxId.Equals(txId)), |
| 260 | + It.Is<GrpcRequestSettings>(grpcRequestSettings => grpcRequestSettings.NodeId == NodeId)) |
| 261 | + ).ThrowsAsync(YdbException.FromServer(StatusIds.Types.StatusCode.NotFound, [])); |
| 262 | + Assert.False(session.IsBroken); |
| 263 | + var ydbException = await Assert.ThrowsAsync<YdbException>(() => session.RollbackTransaction(txId)); |
| 264 | + Assert.Equal(StatusCode.NotFound, ydbException.Code); |
| 265 | + Assert.Equal("Status: NotFound", ydbException.Message); |
| 266 | + tcsSecondMoveAttachStream.TrySetResult(true); |
| 267 | + } |
| 268 | + |
185 | 269 | private TaskCompletionSource<bool> SetupAttachStream() |
186 | 270 | { |
187 | 271 | var tcsSecondMoveAttachStream = new TaskCompletionSource<bool>(); |
|
0 commit comments