Exemple #1
0
func TestInferTableSchema(t *testing.T) {
	c, clean, err := aetest.NewContext()
	if err != nil {
		t.Fatal(err)
	}
	defer clean()
	err = aetools.LoadJSON(c, datastoreStats, aetools.LoadSync)

	s, err := bigquerysync.SchemaForKind(c, "Account")
	if err != nil {
		t.Fatal(err)
	}
	j, _ := json.Marshal(s)
	t.Logf("Decoded schema: '%s'", string(j))

	if len(s.Fields) != 4 {
		t.Errorf("Unexpected field len: %d, expected 4", len(s.Fields))
	}
	for i, f := range s.Fields {
		if f.Name == "" {
			t.Errorf("Name of field %d is empty", i)
		}
		if f.Type == "" {
			t.Errorf("Type of field %d is empty", i)
		}
	}
}
Exemple #2
0
func TestDecodeStatByProperty(t *testing.T) {
	c, clean, err := aetest.NewContext()
	if err != nil {
		t.Fatal(err)
	}
	defer clean()

	err = aetools.LoadJSON(c, datastoreStats, aetools.LoadSync)
	if err != nil {
		t.Log("Unable to load fixtures")
		t.Fatal(err)
	}

	p := new(bigquerysync.StatByProperty)
	name := "Date/Time_CreationDate_Account"
	k := datastore.NewKey(c, bigquerysync.StatByPropertyKind, name, 0, nil)
	err = datastore.Get(c, k, p)
	if err != nil {
		t.Fatal(err)
	}

	if p.Count != 123 {
		t.Errorf("Unexpected p.Count: %d, expecting 123", p.Count)
	}
	if p.Bytes != 45678 {
		t.Errorf("Unexpected p.Bytes: %d, expecting 45678", p.Bytes)
	}
	if p.Type != "Date/Time" {
		t.Errorf("Unexpected p.Type: '%s', expecting 'Date/Time'", p.Type)
	}
	if p.Kind != "Account" {
		t.Errorf("Unexpected p.Account: '%s', expecting 'Account'", p.Kind)
	}
	if p.IndexBytes != 45678 {
		t.Errorf("Unexpected p.IndexBytes: %d, expecting 45678", p.IndexBytes)
	}
	if p.IndexCount != 123 {
		t.Errorf("Unexpected p.IndexCount: %d, expecting 123", p.IndexCount)
	}
	if p.Timestamp.IsZero() {
		t.Errorf("Decoded timestamp is zero")
	}
}
Exemple #3
0
func TestKeyRangeForKind(t *testing.T) {
	c, clean, err := aetest.NewContext()
	if err != nil {
		t.Fatal(err)
	}
	defer clean()
	// No entities: empty range
	ranges := bigquerysync.KeyRangesForKind(c, "RangeTest")
	if len(ranges) != 0 {
		t.Errorf("Unexpected ranges returned: %d, expected 0: %#v", len(ranges), ranges)
	}
	// Setup datastore - __scatter__ is replaced with _scatter__ for testing
	aetools.LoadJSON(c, SampleEntities, aetools.LoadSync)
	// No scatter, single range
	ranges = bigquerysync.KeyRangesForKind(c, "Sample")
	if len(ranges) != 1 {
		t.Errorf("Unexpected ranges without scatters: %v, expected length 1", ranges)
	} else {
		if ranges[0].Start == nil {
			t.Errorf("Unexpected nil start for Sample")
		} else {
			if ranges[0].Start.IntID() != 1 || ranges[0].Start.Kind() != "Sample" {
				t.Errorf("Unexpected start key for Sample: %#v", ranges[0].Start)
			}
			if ranges[0].End != nil {
				t.Errorf("Unexpected end key for Sample: %#v, expected nil", ranges[0].End)
			}
		}
	}
	// Scattered entities: sorted key ranges expected
	ranges = bigquerysync.KeyRangesForKind(c, "RangeTest")
	expected := []struct {
		Start int64
		End   int64
	}{
		{1, 30},
		{30, 50},
		{50, 1000},
		{1000, 0},
	}
	if len(ranges) != len(expected) {
		t.Errorf("Unexpected ranges with scatter: %d, expected 3", len(ranges))
	} else {
		for i, e := range expected {
			r := ranges[i]
			if r.Start == nil {
				t.Errorf("Unexpected nil start at range %d", i)
			} else if r.Start.IntID() != e.Start {
				t.Errorf("Unexpected start at range %d: %#v, expected %d", i, r.Start.IntID(), e.Start)
			}
			if e.End == 0 {
				if r.End != nil {
					t.Errorf("Unexpected end at range %d: %#v, expected nil", i, r.End)
				}
			} else if r.End == nil {
				t.Errorf("Unexpected nil end at range %d, expected %d", i, r.End, e.End)
			} else if r.End.IntID() != e.End {
				t.Errorf("Unexpected end at range %d: %#v, expected %d", i, r.End.IntID(), e.End)
			}
		}
		// Check if all entity keys match
		for i, r := range ranges {
			if r.Start != nil {
				if r.Start.Kind() != "RangeTest" {
					t.Errorf("Unexpected kind at range %d: %s", i, r.Start.Kind())
				}
			}
			if r.End != nil {
				if r.End.Kind() != "RangeTest" {
					t.Errorf("Unexpected kind at range %d: %s", i, r.End.Kind())
				}
			}
		}
	}
}