File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -132,6 +132,31 @@ async fn crud() -> Result<()> {
132
132
Ok ( ( ) )
133
133
}
134
134
135
+ // Tests transactional insert and delete-your-writes cases
136
+ #[ tokio:: test]
137
+ #[ serial]
138
+ async fn insert_duplicate_keys ( ) -> Result < ( ) > {
139
+ clear_tikv ( ) . await ?;
140
+
141
+ let client = TransactionClient :: new ( pd_addrs ( ) ) . await ?;
142
+ // Initialize TiKV store with {foo => bar}
143
+ let mut txn = client. begin_optimistic ( ) . await ?;
144
+ txn. put ( "foo" . to_owned ( ) , "bar" . to_owned ( ) ) . await ?;
145
+ txn. commit ( ) . await ?;
146
+ // Try insert foo again
147
+ let mut txn = client. begin_optimistic ( ) . await ?;
148
+ txn. insert ( "foo" . to_owned ( ) , "foo" . to_owned ( ) ) . await ?;
149
+ assert ! ( txn. commit( ) . await . is_err( ) ) ;
150
+
151
+ // Delete-your-writes
152
+ let mut txn = client. begin_optimistic ( ) . await ?;
153
+ txn. insert ( "foo" . to_owned ( ) , "foo" . to_owned ( ) ) . await ?;
154
+ txn. delete ( "foo" . to_owned ( ) ) . await ?;
155
+ assert ! ( txn. commit( ) . await . is_err( ) ) ;
156
+
157
+ Ok ( ( ) )
158
+ }
159
+
135
160
#[ tokio:: test]
136
161
#[ serial]
137
162
async fn pessimistic ( ) -> Result < ( ) > {
You can’t perform that action at this time.
0 commit comments