-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from alex268/master
Removed ReadyOperation implementation
- Loading branch information
Showing
7 changed files
with
93 additions
and
115 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
66 changes: 0 additions & 66 deletions
66
core/src/main/java/tech/ydb/core/operation/ReadyOperation.java
This file was deleted.
Oops, something went wrong.
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
70 changes: 70 additions & 0 deletions
70
core/src/test/java/tech/ydb/core/operation/OperationImplTest.java
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package tech.ydb.core.operation; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
import com.google.protobuf.Any; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import tech.ydb.core.Result; | ||
import tech.ydb.core.StatusCode; | ||
import tech.ydb.core.grpc.GrpcTransport; | ||
import tech.ydb.proto.OperationProtos; | ||
import tech.ydb.proto.StatusCodesProtos; | ||
import tech.ydb.proto.operation.v1.OperationServiceGrpc; | ||
|
||
/** | ||
* | ||
* @author Aleksandr Gorshenin | ||
*/ | ||
public class OperationImplTest { | ||
private final GrpcTransport mocked = Mockito.mock(GrpcTransport.class); | ||
private final ScheduledExecutorService scheduler = Mockito.mock(ScheduledExecutorService.class); | ||
|
||
@Before | ||
public void setup() { | ||
Mockito.when(mocked.getScheduler()).thenReturn(scheduler); | ||
} | ||
|
||
@Test | ||
public void asyncNotReadyOperationTest() { | ||
OperationProtos.Operation operation = OperationProtos.Operation.newBuilder() | ||
.setStatus(StatusCodesProtos.StatusIds.StatusCode.SUCCESS) | ||
.setId("test-id") | ||
.setReady(false) | ||
.build(); | ||
|
||
Mockito.when(mocked.unaryCall( | ||
Mockito.eq(OperationServiceGrpc.getCancelOperationMethod()), Mockito.any(), Mockito.any() | ||
)).thenReturn(CompletableFuture.completedFuture(Result.success( | ||
OperationProtos.CancelOperationResponse.newBuilder() | ||
.setStatus(StatusCodesProtos.StatusIds.StatusCode.SUCCESS) | ||
.build() | ||
))); | ||
Mockito.when(mocked.unaryCall( | ||
Mockito.eq(OperationServiceGrpc.getForgetOperationMethod()), Mockito.any(), Mockito.any() | ||
)).thenReturn(CompletableFuture.completedFuture(Result.success( | ||
OperationProtos.ForgetOperationResponse.newBuilder() | ||
.setStatus(StatusCodesProtos.StatusIds.StatusCode.BAD_REQUEST) | ||
.build() | ||
))); | ||
Mockito.when(mocked.unaryCall( | ||
Mockito.eq(OperationServiceGrpc.getGetOperationMethod()), Mockito.any(), Mockito.any() | ||
)).thenReturn(CompletableFuture.completedFuture(Result.success( | ||
OperationProtos.GetOperationResponse.newBuilder().setOperation(operation).build() | ||
))); | ||
|
||
AsyncOperation<Any> o = new OperationImpl<>(mocked, operation, OperationProtos.Operation::getResult); | ||
|
||
Assert.assertEquals(scheduler, o.getScheduler()); | ||
Assert.assertEquals("Operation{id=test-id, ready=false}", o.toString()); | ||
Assert.assertFalse(o.isReady()); | ||
Assert.assertNull(o.getValue()); | ||
|
||
Assert.assertEquals(StatusCode.BAD_REQUEST, o.forget().join().getCode()); | ||
Assert.assertEquals(StatusCode.SUCCESS, o.cancel().join().getCode()); | ||
} | ||
} |
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