Files
swift/go/probe/replicator_test.go
Michael Barton f66cb004cd go: object server SYNC report newer files
Have the object server stick a header on the conflict response to SYNC when a
newer file exists.

This allows the replicator to remove local files that are out of date, and maybe
later it can be smart enough to pull down the newer file on non-handoff
replication.

Also adds quarantine for file audit errors on replicate.

Change-Id: If0b83f4899e89a43c5f732008848b62165c355df
2015-05-28 22:19:33 +00:00

90 lines
2.5 KiB
Go

// Copyright (c) 2015 Rackspace
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package probe
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/openstack/swift/go/hummingbird"
)
func TestReplicationHandoff(t *testing.T) {
e := NewEnvironment()
defer e.Close()
// put a file
timestamp := hummingbird.GetTimestamp()
assert.True(t, e.PutObject(0, timestamp, "X"))
// make a drive look unmounted with a handler that always 507s
origHandler := e.servers[1].Config.Handler
e.servers[1].Config.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(507)
})
// run a primary node's replicator
e.replicators[0].Run()
// so it's on the primary nodes that are up
assert.True(t, e.ObjExists(0, timestamp))
assert.True(t, e.ObjExists(2, timestamp))
// and now it's on the handoff node
assert.True(t, e.ObjExists(3, timestamp))
// fix the "unmounted" drive
e.servers[1].Config.Handler = origHandler
// make sure it's not on the newly fixed node yet
assert.False(t, e.ObjExists(1, timestamp))
// run the handoff node's replicator
e.replicators[3].Run()
// it's no longer on the handoff node
assert.False(t, e.ObjExists(3, timestamp))
// make sure it's on all the primary nodes
assert.True(t, e.ObjExists(0, timestamp))
assert.True(t, e.ObjExists(1, timestamp))
assert.True(t, e.ObjExists(2, timestamp))
}
func TestReplicationUnlinkOld(t *testing.T) {
e := NewEnvironment()
defer e.Close()
// put a file to a primary node
timestamp := hummingbird.GetTimestamp()
assert.True(t, e.PutObject(0, timestamp, "X"))
// put a newer file to another primary node
timestamp2 := hummingbird.GetTimestamp()
assert.True(t, e.PutObject(1, timestamp2, "X"))
assert.True(t, e.ObjExists(0, timestamp))
assert.True(t, e.ObjExists(1, timestamp2))
// run the replicator on the server with the old file
e.replicators[0].Run()
// verify the old file was removed by the replicator
assert.False(t, e.ObjExists(0, timestamp))
}