|
| 1 | +// Copyright 2016 The Cockroach Authors. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 12 | +// implied. See the License for the specific language governing |
| 13 | +// permissions and limitations under the License. |
| 14 | +// |
| 15 | +// Author: Peter Mattis (peter@cockroachlabs.com) |
| 16 | + |
| 17 | +package storage_test |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/cockroachdb/cockroach/server" |
| 23 | + "github.com/cockroachdb/cockroach/util/leaktest" |
| 24 | +) |
| 25 | + |
| 26 | +func TestEagerReplication(t *testing.T) { |
| 27 | + defer leaktest.AfterTest(t)() |
| 28 | + store, stopper, _ := createTestStore(t) |
| 29 | + defer stopper.Stop() |
| 30 | + |
| 31 | + // Disable the replica scanner so that we rely on the eager replication code |
| 32 | + // path that occurs after splits. |
| 33 | + store.SetReplicaScannerDisabled(true) |
| 34 | + |
| 35 | + if err := server.WaitForInitialSplits(store.DB()); err != nil { |
| 36 | + t.Fatal(err) |
| 37 | + } |
| 38 | + |
| 39 | + // After the initial splits have been performed, all of the resulting ranges |
| 40 | + // should be present in replicate queue purgatory (because we only have a |
| 41 | + // single store in the test and thus replication cannot succeed). |
| 42 | + expected := server.ExpectedInitialRangeCount() |
| 43 | + if n := store.ReplicateQueuePurgatoryLength(); expected != n { |
| 44 | + t.Fatalf("expected %d replicas in purgatory, but found %d", |
| 45 | + expected, n) |
| 46 | + } |
| 47 | +} |
0 commit comments