// doTestDeleteOldObservations tests deleteOldObservations() method.
doTestDeleteOldObservations tests deleteOldObservations() method.
// doTestDeleteOldObservations tests deleteOldObservations () method .
func doTestDeleteOldObservations(t *testing.T, useMemStore bool) {
	const num = 4
	const currentDayIndex = 10
	store, key, _, err := makeTestStore(num, currentDayIndex, useMemStore)
	if err != nil {
		t.Fatalf("got error [%v] in test store setup", err)
	}
	storage.CheckNumObservations(t, store, key, num)
	d := newTestDispatcher(store, num, 0)
	disposalAgeInDays := uint32(4)
	err = d.deleteOldObservations(key, currentDayIndex, disposalAgeInDays)
	if err != nil {
		t.Errorf("Expected successful update, got error [%v]", err)
		return
	}
	storage.CheckNumObservations(t, store, key, num)
	obValsAfterDeletion := storage.CheckObservations(t, store, key, num)
	for _, obVal := range obValsAfterDeletion {
		if obVal.ArrivalDayIndex <= disposalAgeInDays {
			t.Errorf("Expected ObVal with dayIndex [%d] to be deleted", obVal.Id)
			return
		}
	}
	disposalAgeInDays = uint32(2)
	err = d.deleteOldObservations(key, currentDayIndex, disposalAgeInDays)
	if err != nil {
		t.Errorf("Expected successful update, got error [%v]", err)
		return
	}
	storage.CheckNumObservations(t, store, key, num/2)
	obValsAfterDeletion = storage.CheckObservations(t, store, key, num/2)
	for _, obVal := range obValsAfterDeletion {
		if obVal.ArrivalDayIndex <= disposalAgeInDays {
			t.Errorf("Expected ObVal with dayIndex [%d] to be deleted", obVal.Id)
			return
		}
	}
	disposalAgeInDays = uint32(0)
	err = d.deleteOldObservations(key, currentDayIndex, disposalAgeInDays)
	if err != nil {
		t.Errorf("Expected successful update, got error [%v]", err)
		return
	}
	storage.CheckNumObservations(t, store, key, 0)
	storage.ResetStoreForTesting(d.store, true)
}
func doTestDeleteOldObservations ( t * testing . T , useMemStore bool ) { const num = 4 const currentDayIndex = 10 store , key , _ , err := makeTestStore ( num , currentDayIndex , useMemStore ) if err != nil { t . Fatalf ( " " , err ) } storage . CheckNumObservations ( t , store , key , num ) d := newTestDispatcher ( store , num , 0 ) disposalAgeInDays := uint32 ( 4 ) err = d . deleteOldObservations ( key , currentDayIndex , disposalAgeInDays ) if err != nil { t . Errorf ( " " , err ) return } storage . CheckNumObservations ( t , store , key , num ) obValsAfterDeletion := storage . CheckObservations ( t , store , key , num ) for _ , obVal := range obValsAfterDeletion { if obVal . ArrivalDayIndex <= disposalAgeInDays { t . Errorf ( " " , obVal . Id ) return } } disposalAgeInDays = uint32 ( 2 ) err = d . deleteOldObservations ( key , currentDayIndex , disposalAgeInDays ) if err != nil { t . Errorf ( " " , err ) return } storage . CheckNumObservations ( t , store , key , num / 2 ) obValsAfterDeletion = storage . CheckObservations ( t , store , key , num / 2 ) for _ , obVal := range obValsAfterDeletion { if obVal . ArrivalDayIndex <= disposalAgeInDays { t . Errorf ( " " , obVal . Id ) return } } disposalAgeInDays = uint32 ( 0 ) err = d . deleteOldObservations ( key , currentDayIndex , disposalAgeInDays ) if err != nil { t . Errorf ( " " , err ) return } storage . CheckNumObservations ( t , store , key , 0 ) storage . ResetStoreForTesting ( d . store , true ) }
doTestDeleteOldObservations tests deleteOldObservations() method.
doTestDeleteOldObservations tests deleteOldObservations () method .
// make test dispatcher by setting threshold and frequency to "0" and // batchsize to max |num| for immediate dispatch. // Dispose off any older messages that have a dayIndex less than "4". // none of the stored observations gets deleted // Dispose off any older messages that have a dayIndex less than "2". // this list must contain exactly half the observations // Dispose off all messages by specifying dayIndex "0". // all the observations for the given key should be deleted // reset store