| 123 | } |
| 124 | |
| 125 | func (m *mockKV) CAS(p *consul.KVPair, _ *consul.WriteOptions) (bool, *consul.WriteMeta, error) { |
| 126 | level.Debug(m.logger).Log("msg", "CAS", "key", p.Key, "modify_index", p.ModifyIndex, "value", fmt.Sprintf("%.40q", p.Value)) |
| 127 | |
| 128 | m.mtx.Lock() |
| 129 | defer m.mtx.Unlock() |
| 130 | existing, ok := m.kvps[p.Key] |
| 131 | if ok && existing.ModifyIndex != p.ModifyIndex { |
| 132 | return false, nil, nil |
| 133 | } |
| 134 | |
| 135 | m.current++ |
| 136 | if ok { |
| 137 | existing.Value = p.Value |
| 138 | existing.ModifyIndex = m.current |
| 139 | } else { |
| 140 | m.kvps[p.Key] = &consul.KVPair{ |
| 141 | Key: p.Key, |
| 142 | Value: p.Value, |
| 143 | CreateIndex: m.current, |
| 144 | ModifyIndex: m.current, |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | m.cond.Broadcast() |
| 149 | return true, nil, nil |
| 150 | } |
| 151 | |
| 152 | func (m *mockKV) Get(key string, q *consul.QueryOptions) (*consul.KVPair, *consul.QueryMeta, error) { |
| 153 | level.Debug(m.logger).Log("msg", "Get", "key", key, "wait_index", q.WaitIndex) |