Пример #1
0
func Test_Should_retrieve_from_multiple_puts(t *testing.T) {
	// Arrange
	eventSet := goes.NewEmptyEventSet()
	eventSet, _ = eventSet.Put([]goes.Event{
		{1, MakeByteSlice(10)},
		{2, MakeByteSlice(12)},
		{3, MakeByteSlice(14)},
	}...)

	// Act
	eventSet, _ = eventSet.Put([]goes.Event{
		{4, MakeByteSlice(16)},
		{5, MakeByteSlice(18)},
		{6, MakeByteSlice(20)},
	}...)

	// Act
	events, err := eventSet.GetSlice(0, 6)

	// Assert
	IsNil(t, err, "Should not have failed Get")
	AreEqual(t, 6, events.Count(), "Should have brought back all records")
	AreEqual(t, uint16(2), events.EventTypeAt(1), "Should have retained initial headers")
	AreEqual(t, uint16(5), events.EventTypeAt(4), "Should have appended additional headers")
}
func Run_PutGet_Trim2(b *testing.B, eventSize int) {
	//b.StopTimer()
	//runtime.GC()
	event := goes.Event{
		EventType: 1,
		Data:      make([]byte, eventSize),
	}
	/*
		eventSets := make([]*goes.EventSet, b.N)
		for i := 0; i < b.N; i++ {
			eventSets[i] = goes.NewEmptyEventSet()
		}
	*/
	//eventSet := goes.NewEmptyEventSet()
	b.ResetTimer()
	for index := 0; index < b.N; index++ {
		eventSet := goes.NewEmptyEventSet()
		//for i := 0; i < 10; i++ {
		////eventSets[index], _ = eventSets[index].Put(event)
		//}
		//for i := 0; i < 10; i++ {
		////eventSets[index].Get()
		//}

		eventSet, _ = eventSet.Put(event)
		eventSet.GetSlice(0, 1)
	}
}
Пример #3
0
func Test_Should_return_err_for_invalid_range(t *testing.T) {
	// Arrange
	eventSet := goes.NewEmptyEventSet()
	ranges := []struct {
		Start int
		Stop  int
	}{
		{-1, 0},
		{4, 1},
		{2, 1},
		{1, 1},
	}

	// Act
	eventSet2, _ := eventSet.Put([]goes.Event{
		{1, MakeByteSlice(10)},
		{2, MakeByteSlice(12)},
		{3, MakeByteSlice(14)},
	}...)

	// Assert
	for _, r := range ranges {
		_, err := eventSet2.GetSlice(r.Start, r.Stop)
		IsNotNil(t, err, fmt.Sprintf("Should have failed for [%d, %d]", r.Start, r.Stop))
	}

}
func Run_PutGet_Spread(b *testing.B, eventSize int, batchSize int, batchCount int) {
	runtime.GC()
	eventData := make([]byte, eventSize)
	for i := 0; i < eventSize; i++ {
		eventData[i] = byte(i | 0xFF)
	}
	batch := make([]goes.Event, batchSize)
	for i := 0; i < batchSize; i++ {
		batch[i] = goes.Event{
			EventType: uint16(i),
			Data:      eventData,
		}
	}

	b.ResetTimer()
	b.StopTimer()
	for i := 0; i < b.N; i++ {
		//go func() {
		//b.StopTimer()
		/*
			gcTimer++
			if gcTimer == gcTime {
				//b.StopTimer()
				runtime.GC()
				//b.StartTimer()
				gcTimer = 0
			}
		*/

		store := make([]*goes.EventSet, batchCount)
		for index := 0; index < batchCount; index++ {
			store[index] = goes.NewEmptyEventSet()
		}

		b.StartTimer()

		for index := 0; index < batchCount; index++ {
			for i := 0; i < batchCount; i++ {
				store[index], _ = store[index].Put(batch...)
			}
		}

		for index := 0; index < batchCount; index++ {
			store[index].GetSlice(0, 1)
		}

		b.StopTimer()
		//}()
		//count++
	}
	/*
		for count < b.N {
			time.Sleep(10 * time.Nanosecond)
		}
	*/
}
Пример #5
0
func Test_Should_return_err_for_event_over_max_size(t *testing.T) {
	// Arrange
	eventSet := goes.NewEmptyEventSet()

	// Act
	eventSet, err := eventSet.Put(goes.Event{1, MakeByteSlice(int(goes.MaxUint16) + 1)})

	// Assert
	IsNotNil(t, err, "Should have failed to put event")
}
Пример #6
0
func Test_Should_return_error_if_end_index_less_than_zero(t *testing.T) {
	// Arrange
	eventSet := goes.NewEmptyEventSet()

	// Act
	_, err := eventSet.GetSlice(0, -1)

	// Assert
	IsNotNil(t, err, "Should have failed due to end index bounds")
}
Пример #7
0
func Test_Should_checksum_successfully_for_empty_dataset(t *testing.T) {
	// Arrange
	eventSet := goes.NewEmptyEventSet()

	// Act
	result := eventSet.CheckSum()

	// Assert
	IsNil(t, result, "Should have passed check sum")
}
Пример #8
0
func Test_Should_return_empty_event_slice_for_empty_set(t *testing.T) {
	// Arrange
	eventSet := goes.NewEmptyEventSet()

	// Act
	events, err := eventSet.GetSlice(0, 1)

	// Assert
	IsNil(t, err, "Should have allowed read from empty set")
	AreEqual(t, 0, events.Count(), "Should have returned an empty slice")
}
Пример #9
0
func Test_Should_be_able_to_resize_header_slice(t *testing.T) {
	// Arrange
	eventSet := goes.NewEmptyEventSet()
	events := make([]goes.Event, (goes.HEADER_SLICE_SIZE/8)+1)
	for i := range events {
		events[i] = goes.Event{uint16(i), MakeByteSlice(i)}
	}

	// Act
	eventSet, _ = eventSet.Put(events...)

	// Assert
	IsNotNil(t, eventSet, "Should have returned valid event set")
}
Пример #10
0
func Test_Should_return_err_if_event_is_too_large(t *testing.T) {
	// Arrange
	eventSet := goes.NewEmptyEventSet()

	// Act
	eventSet, err := eventSet.Put([]goes.Event{
		{1, MakeByteSlice(10000)},
		{2, MakeByteSlice(12000)},
		{3, MakeByteSlice(140000)}, // make it 1400000
	}...)

	// Assert
	IsNotNil(t, err, "Should have throw event too large error")
}
Пример #11
0
func Test_Should_put_slice_of_events_in_batch(t *testing.T) {
	// Arrange
	eventSet := goes.NewEmptyEventSet()

	// Act
	eventSet, err := eventSet.Put([]goes.Event{
		{1, MakeByteSlice(10)},
		{2, MakeByteSlice(12)},
		{3, MakeByteSlice(14)},
	}...)

	// Assert
	IsNil(t, err, "Should have put events")
	AreEqual(t, 3, eventSet.Count(), "Should have put all 3 values")
}
Пример #12
0
func Test_Should_checksum_successfully_for_valid_dataset(t *testing.T) {
	// Arrange
	eventSet := goes.NewEmptyEventSet()
	eventSet, _ = eventSet.Put([]goes.Event{
		{1, MakeByteSlice(10)},
		{2, MakeByteSlice(12)},
		{3, MakeByteSlice(14)},
	}...)

	// Act
	err := eventSet.CheckSum()

	// Assert
	IsNil(t, err, "Should not have failed check sum")
}
Пример #13
0
func Test_Should_limit_end_index_to_max_available_from_set(t *testing.T) {
	// Arrange
	eventSet := goes.NewEmptyEventSet()
	eventSet, err := eventSet.Put([]goes.Event{
		{1, MakeByteSlice(10)},
		{2, MakeByteSlice(12)},
		{3, MakeByteSlice(14)},
		{4, MakeByteSlice(16)},
		{5, MakeByteSlice(18)},
	}...)

	// Act
	events, err := eventSet.GetSlice(2, 40)

	// Assert
	IsNil(t, err, "Should have allowed read slice from populated set")
	AreEqual(t, 3, events.Count(), "Should have returned three results")
}
Пример #14
0
func Run_PutGet(b *testing.B, eventSize int, batchSize int, batchCount int) {
	runtime.GC()
	//eventSet := goes.NewEmptyEventSet()
	eventData := make([]byte, eventSize)
	for i := 0; i < eventSize; i++ {
		eventData[i] = byte(i | 0xFF)
	}
	batch := make([]goes.Event, batchSize)
	for i := 0; i < batchSize; i++ {
		batch[i] = goes.Event{
			EventType: uint16(i),
			Data:      eventData,
		}
	}

	//b.ResetTimer()
	//b.StopTimer()
	for i := 0; i < b.N; i++ {
		/*
			gcTimer++
			if gcTimer == gcTime {
				//b.StopTimer()
				runtime.GC()
				//b.StartTimer()
				gcTimer = 0
			}
		*/

		eventSet := goes.NewEmptyEventSet()
		//b.StartTimer()

		for index := 0; index < batchCount; index++ {
			eventSet, _ = eventSet.Put(batch...)
			//eventSet.Put(batch...)
		}

		eventSet.GetSlice(0, 1)
		//b.StopTimer()
	}
}
Пример #15
0
func Test_Should_return_correct_sub_range_from_set(t *testing.T) {
	// Arrange
	eventSet := goes.NewEmptyEventSet()
	eventSet, err := eventSet.Put([]goes.Event{
		{1, MakeByteSlice(10)},
		{2, MakeByteSlice(12)},
		{3, MakeByteSlice(14)},
		{4, MakeByteSlice(16)},
		{5, MakeByteSlice(18)},
	}...)

	// Act
	events, err := eventSet.GetSlice(2, 4)

	// Assert
	IsNil(t, err, "Should have allowed read slice from populated set")
	AreEqual(t, 2, events.Count(), "Should have returned two results")
	AreEqual(t, uint16(3), events.EventTypeAt(0), "Should have returned the second event")
	AreEqual(t, 14, len(events.DataAt(0)), "Should have returned 14 bytes of data")
	AreEqual(t, uint16(4), events.EventTypeAt(1), "Should have returned the third event")
	AreEqual(t, 16, len(events.DataAt(1)), "Should have returned 16 bytes of data")

}
Пример #16
0
func Test_Should_expand_headers(t *testing.T) {
	// Arrange
	eventSet := goes.NewEmptyEventSet()
	eventSet, _ = eventSet.Put([]goes.Event{
		{1, MakeByteSlice(10)},
	}...)

	// Act
	batch := new([goes.HEADER_SLICE_SIZE]goes.Event)
	for i := 0; i < goes.HEADER_SLICE_SIZE; i++ {
		batch[i] = goes.Event{uint16(i), MakeByteSlice(i)}
	}
	eventSet, _ = eventSet.Put(batch[:]...)

	// Act
	events, err := eventSet.GetSlice(0, goes.HEADER_SLICE_SIZE)

	// Assert
	IsNil(t, err, "Should not have failed Get")
	AreEqual(t, len(batch), events.Count(), "Should have brought back all records")
	AreEqual(t, uint16(0), events.EventTypeAt(1), "Should have retained initial headers")
	AreEqual(t, uint16(3), events.EventTypeAt(4), "Should have appended additional headers")
}
Пример #17
0
func Run_PutGet2(b *testing.B, eventSize int, batchSize int, batchCount int) {
	runtime.GC()
	//eventSet := goes.NewEmptyEventSet()
	eventData := make([]byte, eventSize)
	for i := 0; i < eventSize; i++ {
		eventData[i] = byte(i | 0xFF)
	}
	batch := make([]goes.Event, batchSize)
	for i := 0; i < batchSize; i++ {
		batch[i] = goes.Event{
			EventType: uint16(i),
			Data:      eventData,
		}
	}

	b.ResetTimer()
	b.StopTimer()
	var err error
	for i := 0; i < b.N; i++ {
		gcTimer++
		if gcTimer == gcTime {
			//b.StopTimer()
			runtime.GC()
			//b.StartTimer()
			gcTimer = 0
		}

		eventSet := goes.NewEmptyEventSet()
		for index := 0; index < batchCount; index++ {
			//b.StartTimer()

			eventSet, err = eventSet.Put(batch...)
			if err != nil {
				log.Printf("Put failed: %s", err)
				b.Fail()
			}

			//b.StopTimer()
		}

		b.StartTimer()
		_, err := eventSet.GetSlice(0, 1)
		//b.Logf("Read: %d", len(events))
		b.StopTimer()
		if err != nil {
			b.Fail()
		}
		/*
			if err := eventSet.CheckSum(); err != nil {
				b.Fail()
			}
		*/

		/*
			if _, err := eventSet.Get(); err == nil {
				//if len(events) != batchSize*batchCount {
				//	log.Printf("Events[ %d, %d ]: %d, %d, %d", len(events), cap(events), i, batchSize, batchCount)
				//	b.Fail()
				//}
			} else {
				log.Printf("Put failed: %s", err)
				b.Fail()
			}
		*/

	}
}