Exemplo n.º 1
0
func TestDBTransactionIO_DeleteAll_IsIsolated(t *testing.T) {
	key1 := authtu.TestBucketName()
	key2 := authtu.TestBucketName() + "-2"

	txio := testDBTransactionIOWithRootKey(key1)
	txio2 := testDBTransactionIOWithRootKey(key2)

	if err := txio.DeleteAllTransactions(); err != nil {
		t.Errorf("DeleteTransactions failed: %v", err)
	}
	if err := txio2.DeleteAllTransactions(); err != nil {
		t.Errorf("DeleteTransactions failed: %v", err)
	}

	tx := inodedb.DBTransaction{TxID: 100, Ops: []inodedb.DBOperation{
		&inodedb.CreateNodeOp{NodeLock: inodedb.NodeLock{2, 123456}, OrigPath: "/hoge.txt", Type: inodedb.FileNodeT},
		&inodedb.HardLinkOp{NodeLock: inodedb.NodeLock{1, inodedb.NoTicket}, Name: "hoge.txt", TargetID: 2},
	}}
	if err := txio.AppendTransaction(tx); err != nil {
		t.Errorf("AppendTransaction failed: %v", err)
	}
	tx2 := inodedb.DBTransaction{TxID: 200, Ops: []inodedb.DBOperation{
		&inodedb.CreateNodeOp{NodeLock: inodedb.NodeLock{2, 123456}, OrigPath: "/fuga.txt", Type: inodedb.FileNodeT},
		&inodedb.HardLinkOp{NodeLock: inodedb.NodeLock{1, inodedb.NoTicket}, Name: "fuga.txt", TargetID: 2},
	}}
	if err := txio2.AppendTransaction(tx2); err != nil {
		t.Errorf("AppendTransaction failed: %v", err)
	}

	if err := txio.DeleteAllTransactions(); err != nil {
		t.Errorf("DeleteTransactions failed: %v", err)
	}

	{
		txs, err := txio.QueryTransactions(inodedb.AnyVersion)
		if err != nil {
			t.Errorf("QueryTransactions failed: %v", err)
			return
		}
		if len(txs) != 0 {
			t.Errorf("Tx queried after DeleteAllTransactions")
			return
		}
	}
	{
		txs, err := txio2.QueryTransactions(inodedb.AnyVersion)
		if err != nil {
			t.Errorf("QueryTransactions failed: %v", err)
			return
		}
		if len(txs) != 1 {
			t.Errorf("DeleteAllTransactions deleted txlog on separate rootKey")
			return
		}

		if !reflect.DeepEqual(txs[0], tx2) {
			t.Errorf("serdes mismatch: %+v", txs)
		}
	}
}
Exemplo n.º 2
0
func testGCSBlobStore() *gcs.GCSBlobStore {
	bs, err := gcs.NewGCSBlobStore(
		authtu.TestConfig().ProjectName,
		authtu.TestBucketName(),
		authtu.TestTokenSource(),
		flags.O_RDWR,
	)
	if err != nil {
		log.Fatalf("Failed to create GCSBlobStore: %v", err)
	}
	return bs
}
Exemplo n.º 3
0
func TestGlobalLocker_ActAsMutex(t *testing.T) {
	l1 := datastore.NewGlobalLocker(authtu.TestDSConfig(authtu.TestBucketName()), "otaru-unittest-1", "hogefuga")
	l2 := datastore.NewGlobalLocker(authtu.TestDSConfig(authtu.TestBucketName()), "otaru-unittest-2", "foobar")

	if err := l1.ForceUnlock(); err != nil {
		t.Errorf("ForceUnlock() failed: %v", err)
		return
	}

	// l1 takes lock. l2 lock should fail.
	if err := l1.Lock(); err != nil {
		t.Errorf("l1.Lock() failed: %v", err)
	}
	err := l2.Lock()
	if _, ok := err.(*datastore.ErrLockTaken); !ok {
		t.Errorf("l2.Lock() unexpected (no) err: %v", err)
	}

	if err := l1.Unlock(); err != nil {
		t.Errorf("l1.Unlock() failed: %v", err)
	}
}
Exemplo n.º 4
0
func TestGlobalLocker_LockUnlock(t *testing.T) {
	l := datastore.NewGlobalLocker(authtu.TestDSConfig(authtu.TestBucketName()), "otaru-unittest", "unittest desuyo-")

	if err := l.ForceUnlock(); err != nil {
		t.Errorf("ForceUnlock() failed: %v", err)
		return
	}

	if err := l.Lock(); err != nil {
		t.Errorf("Lock() failed: %v", err)
	}

	if err := l.Unlock(); err != nil {
		t.Errorf("Unlock() failed: %v", err)
	}
}
Exemplo n.º 5
0
func TestINodeDBSSLocator_PutLocate(t *testing.T) {
	loc := datastore.NewINodeDBSSLocator(authtu.TestDSConfig(authtu.TestBucketName()))

	if _, err := loc.DeleteAll(); err != nil {
		t.Errorf("DeleteAll failed unexpectedly: %v", err)
		return
	}

	bp, err := loc.Locate(0)
	if err != datastore.EEMPTY {
		t.Errorf("Locate() when no entry should fail, but succeeded.")
	}

	if err := loc.Put("META-snapshot123", 123); err != nil {
		t.Errorf("Put failed unexpectedly: %v", err)
		return
	}
	if err := loc.Put("META-snapshot231", 231); err != nil {
		t.Errorf("Put failed unexpectedly: %v", err)
		return
	}

	bp, err = loc.Locate(0)
	if err != nil {
		t.Errorf("Locate failed unexpectedly: %v", err)
		return
	}
	if bp != "META-snapshot231" {
		t.Errorf("Locate returned unexpected bp: %v", bp)
		return
	}

	bp, err = loc.Locate(1)
	if err != nil {
		t.Errorf("Locate failed unexpectedly: %v", err)
		return
	}
	if bp != "META-snapshot123" {
		t.Errorf("Locate returned unexpected bp: %v", bp)
		return
	}

	if err := loc.Put("META-snapshot345", 345); err != nil {
		t.Errorf("Put failed unexpectedly: %v", err)
		return
	}

	bp, err = loc.Locate(0)
	if err != nil {
		t.Errorf("Locate failed unexpectedly: %v", err)
		return
	}
	if bp != "META-snapshot345" {
		t.Errorf("Locate returned unexpected bp: %v", bp)
		return
	}

	bps, err := loc.DeleteAll()
	if err != nil {
		t.Errorf("DeleteAll failed unexpectedly: %v", err)
		return
	}
	sort.Strings(bps)
	if !reflect.DeepEqual([]string{
		"META-snapshot123",
		"META-snapshot231",
		"META-snapshot345",
	}, bps) {
		t.Errorf("DeleteAll returned unexpected blobpaths: %v", bps)
		return
	}
}
func testRootKey() string { return authtu.TestBucketName() + "-blobstoredbstatesnapshotio_test" }
Exemplo n.º 7
0
func testDBTransactionIO() *datastore.DBTransactionLogIO {
	return testDBTransactionIOWithRootKey(authtu.TestBucketName())
}