Beispiel #1
0
func tryTxn(kv engine.MVCCKeyValue) (string, error) {
	var txn roachpb.Transaction
	if err := maybeUnmarshalInline(kv.Value, &txn); err != nil {
		return "", err
	}
	return txn.String() + "\n", nil
}
Beispiel #2
0
func TestTransactionString(t *testing.T) {
	txnID, err := uuid.FromBytes([]byte("ת\x0f^\xe4-Fؽ\xf7\x16\xe4\xf9\xbe^\xbe"))
	if err != nil {
		t.Fatal(err)
	}
	ts1 := hlc.Timestamp{WallTime: 10, Logical: 11}
	txn := roachpb.Transaction{
		TxnMeta: enginepb.TxnMeta{
			Isolation: enginepb.SERIALIZABLE,
			Key:       roachpb.Key("foo"),
			ID:        &txnID,
			Epoch:     2,
			Timestamp: hlc.Timestamp{WallTime: 20, Logical: 21},
			Priority:  957356782,
		},
		Name:          "name",
		Status:        roachpb.COMMITTED,
		LastHeartbeat: &ts1,
		OrigTimestamp: hlc.Timestamp{WallTime: 30, Logical: 31},
		MaxTimestamp:  hlc.Timestamp{WallTime: 40, Logical: 41},
	}
	expStr := `"name" id=d7aa0f5e key="foo" rw=false pri=44.58039917 iso=SERIALIZABLE stat=COMMITTED ` +
		`epo=2 ts=0.000000020,21 orig=0.000000030,31 max=0.000000040,41 wto=false rop=false`

	if str := txn.String(); str != expStr {
		t.Errorf("expected txn %s; got %s", expStr, str)
	}

	var txnEmpty roachpb.Transaction
	_ = txnEmpty.String() // prevent regression of NPE

	cmd := storagebase.RaftCommand{
		BatchRequest: &roachpb.BatchRequest{},
	}
	cmd.BatchRequest.Txn = &txn
	if actStr, idStr := fmt.Sprintf("%s", &cmd), txnID.String(); !strings.Contains(actStr, idStr) {
		t.Fatalf("expected to find '%s' in '%s'", idStr, actStr)
	}
}