| 117 | } |
| 118 | |
| 119 | func testInsertLarge(t *testing.T, kv sorted.KeyValue) { |
| 120 | largeKey := make([]byte, sorted.MaxKeySize-1) |
| 121 | // setting all the bytes because postgres whines about an invalid byte sequence |
| 122 | // otherwise |
| 123 | for k := range largeKey { |
| 124 | largeKey[k] = 'A' |
| 125 | } |
| 126 | largeKey[sorted.MaxKeySize-2] = 'B' |
| 127 | largeValue := make([]byte, sorted.MaxValueSize-1) |
| 128 | for k := range largeValue { |
| 129 | largeValue[k] = 'A' |
| 130 | } |
| 131 | largeValue[sorted.MaxValueSize-2] = 'B' |
| 132 | |
| 133 | // insert with large key |
| 134 | if err := kv.Set(string(largeKey), "whatever"); err != nil { |
| 135 | t.Fatalf("Insertion of large key failed: %v", err) |
| 136 | } |
| 137 | |
| 138 | // and verify we can get it back, i.e. that the key hasn't been truncated. |
| 139 | it := kv.Find(string(largeKey), "") |
| 140 | if !it.Next() || it.Key() != string(largeKey) || it.Value() != "whatever" { |
| 141 | it.Close() |
| 142 | t.Fatalf("Find(largeKey) = %q, %q; want %q, %q", it.Key(), it.Value(), largeKey, "whatever") |
| 143 | } |
| 144 | it.Close() |
| 145 | |
| 146 | // insert with large value |
| 147 | if err := kv.Set("whatever", string(largeValue)); err != nil { |
| 148 | t.Fatalf("Insertion of large value failed: %v", err) |
| 149 | } |
| 150 | // and verify we can get it back, i.e. that the value hasn't been truncated. |
| 151 | if v, err := kv.Get("whatever"); err != nil || v != string(largeValue) { |
| 152 | t.Fatalf("get(\"whatever\") = %q, %v; want %q", v, err, largeValue) |
| 153 | } |
| 154 | |
| 155 | // insert with large key and large value |
| 156 | if err := kv.Set(string(largeKey), string(largeValue)); err != nil { |
| 157 | t.Fatalf("Insertion of large key and value failed: %v", err) |
| 158 | } |
| 159 | // and verify we can get them back |
| 160 | it = kv.Find(string(largeKey), "") |
| 161 | defer it.Close() |
| 162 | if !it.Next() || it.Key() != string(largeKey) || it.Value() != string(largeValue) { |
| 163 | t.Fatalf("Find(largeKey) = %q, %q; want %q, %q", it.Key(), it.Value(), largeKey, largeValue) |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | func testInsertTooLarge(t *testing.T, kv sorted.KeyValue) { |
| 168 | largeKey := make([]byte, sorted.MaxKeySize+1) |