| 284 | } |
| 285 | |
| 286 | func (m *mockKV) doPut(op clientv3.Op) (clientv3.OpResponse, error) { |
| 287 | keyBytes := op.KeyBytes() |
| 288 | valBytes := op.ValueBytes() |
| 289 | key := string(keyBytes) |
| 290 | |
| 291 | var newVal mvccpb.KeyValue |
| 292 | oldVal, ok := m.values[key] |
| 293 | |
| 294 | if ok { |
| 295 | newVal = oldVal |
| 296 | newVal.Version = newVal.Version + 1 |
| 297 | newVal.ModRevision = newVal.ModRevision + 1 |
| 298 | newVal.Value = valBytes |
| 299 | } else { |
| 300 | newVal = mvccpb.KeyValue{ |
| 301 | Key: keyBytes, |
| 302 | Value: valBytes, |
| 303 | Version: 1, |
| 304 | CreateRevision: 1, |
| 305 | ModRevision: 1, |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | m.values[key] = newVal |
| 310 | m.sendEvent(clientv3.Event{ |
| 311 | Type: mvccpb.PUT, |
| 312 | Kv: &newVal, |
| 313 | }) |
| 314 | |
| 315 | res := clientv3.PutResponse{} |
| 316 | return res.OpResponse(), nil |
| 317 | } |
| 318 | |
| 319 | func (m *mockKV) doTxn(op clientv3.Op) (clientv3.OpResponse, error) { |
| 320 | cmps, thens, elses := op.Txn() |