27
27
28
28
import com .google .api .core .ApiFuture ;
29
29
import com .google .api .core .ApiFutures ;
30
- import com .google .cloud .spanner .AsyncRunner .AsyncWork ;
31
30
import com .google .cloud .spanner .TransactionRunner .TransactionCallable ;
32
31
import java .util .concurrent .ExecutorService ;
33
32
import java .util .concurrent .Executors ;
@@ -57,14 +56,7 @@ public void testAsyncRunReturnsResultAndCommitResponse() {
57
56
58
57
AsyncRunnerImpl runner = new AsyncRunnerImpl (delegate );
59
58
ApiFuture <Object > result =
60
- runner .runAsync (
61
- new AsyncWork <Object >() {
62
- @ Override
63
- public ApiFuture <Object > doWorkAsync (TransactionContext txn ) {
64
- return ApiFutures .immediateFuture (expectedResult );
65
- }
66
- },
67
- executor );
59
+ runner .runAsync (txn -> ApiFutures .immediateFuture (expectedResult ), executor );
68
60
69
61
assertSame (expectedResult , get (result ));
70
62
assertSame (expectedCommitResponse , get (runner .getCommitResponse ()));
@@ -105,14 +97,7 @@ public void testGetCommitResponseReturnsErrorIfRunFails() {
105
97
when (delegate .getCommitResponse ()).thenThrow (expectedException );
106
98
107
99
AsyncRunnerImpl runner = new AsyncRunnerImpl (delegate );
108
- runner .runAsync (
109
- new AsyncWork <Void >() {
110
- @ Override
111
- public ApiFuture <Void > doWorkAsync (TransactionContext txn ) {
112
- return ApiFutures .immediateFailedFuture (expectedException );
113
- }
114
- },
115
- executor );
100
+ runner .runAsync (txn -> ApiFutures .immediateFailedFuture (expectedException ), executor );
116
101
117
102
try {
118
103
get (runner .getCommitResponse ());
@@ -130,24 +115,10 @@ public void testRunAyncFailsIfCalledMultipleTimes() {
130
115
when (delegate .run (any (TransactionCallable .class ))).thenReturn (result );
131
116
132
117
AsyncRunnerImpl runner = new AsyncRunnerImpl (delegate );
133
- runner .runAsync (
134
- new AsyncWork <Object >() {
135
- @ Override
136
- public ApiFuture <Object > doWorkAsync (TransactionContext txn ) {
137
- return ApiFutures .immediateFuture (result );
138
- }
139
- },
140
- executor );
118
+ runner .runAsync (txn -> ApiFutures .immediateFuture (result ), executor );
141
119
142
120
try {
143
- runner .runAsync (
144
- new AsyncWork <Object >() {
145
- @ Override
146
- public ApiFuture <Object > doWorkAsync (TransactionContext txn ) {
147
- return ApiFutures .immediateFuture (null );
148
- }
149
- },
150
- executor );
121
+ runner .runAsync (txn -> ApiFutures .immediateFuture (null ), executor );
151
122
fail ("missing expected exception" );
152
123
} catch (IllegalStateException e ) {
153
124
assertTrue (e .getMessage ().contains ("runAsync() can only be called once" ));
0 commit comments