Exemplo n.º 1
0
// ------------------------------------------
//
//
// End 2 End test of the MTAContainer with Failure strategy
// and RoundRobinSchedule.
//
//
func TestEnd2End(t *testing.T) {

	//	mg := mailgunprovider.New(utilities.GetLogger("MG"),mailgunprovider.BitLabConfig("09fe27"),NewMockFailureStrategy());
	//	az := amazonsesprovider.New(utilities.GetLogger("MG"),amazonsesprovider.BitLabConfig("09fe27"),NewMockFailureStrategy());
	//  sg := sendgridprovider.New(utilities.GetLogger("MG"),sendgridprovider.BitLabConfig("09fe27"),NewMockFailureStrategy());
	var provider = loopbackprovider.New(utilities.GetLogger("loop1"), mtacontainer.NewThressHoldFailureStrategy(12))

	scheduler := mtacontainer.NewRoundRobinScheduler([]mtacontainer.MTAProvider{provider})

	container := mtacontainer.New(scheduler)

	mail1 := FreshTestMail(provider, "*****@*****.**")
	mail2 := FreshTestMail(provider, "*****@*****.**")
	mail3 := FreshTestMail(provider, "*****@*****.**")

	container.GetOutgoing() <- mail1
	container.GetOutgoing() <- mail2
	container.GetOutgoing() <- mail3

	go func() {
		<-container.GetIncoming()
	}()

	i := 0
	for {
		select {
		case e := <-container.GetEvent():
			log.Println("Reading event from container: " + e.GetError().Error())
			if i == 2 {
				return
			}
			i = i + 1
		}
	}
}
func TestMTAProvider_RoundRobinScheduler_test(t *testing.T) {

	var mockP1 = NewMockMTAProvider(t).(*MockMTAProvider)
	var mockP2 = NewMockMTAProvider(t).(*MockMTAProvider)

	var roundRobinScheduler = mtacontainer.NewRoundRobinScheduler([]mtacontainer.MTAProvider{mockP1, mockP2})

	container := mtacontainer.New(roundRobinScheduler)

	mail1 := FreshTestMail(mockP1, "mail1")
	mail2 := FreshTestMail(mockP2, "mail2")
	mail3 := FreshTestMail(mockP2, "mail3")
	mail4 := FreshTestMail(mockP2, "mail4")
	mail5 := FreshTestMail(mockP2, "mail5")
	mail6 := FreshTestMail(mockP2, "mail6")
	mail7 := FreshTestMail(mockP2, "mail7")
	mail8 := FreshTestMail(mockP2, "mail8")
	mail9 := FreshTestMail(mockP2, "mail9")
	mail10 := FreshTestMail(mockP2, "mail10")

	mockP1.ExpectOutMail(mail1)
	mockP2.ExpectOutMail(mail2)
	container.GetOutgoing() <- mail1
	mockP1.DoOutgoingEmail()
	container.GetOutgoing() <- mail2
	mockP2.DoOutgoingEmail()

	mockP1.ExpectOutMail(mail3)
	mockP2.ExpectOutMail(mail4)
	container.GetOutgoing() <- mail3
	mockP1.DoOutgoingEmail()
	container.GetOutgoing() <- mail4
	mockP2.DoOutgoingEmail()

	mockP1.ExpectOutMail(mail5)
	mockP2.ExpectOutMail(mail6)
	container.GetOutgoing() <- mail5
	mockP1.DoOutgoingEmail()
	container.GetOutgoing() <- mail6
	mockP2.DoOutgoingEmail()

	mockP1.ExpectOutMail(mail7)
	mockP2.ExpectOutMail(mail8)
	container.GetOutgoing() <- mail7
	mockP1.DoOutgoingEmail()
	container.GetOutgoing() <- mail8
	mockP2.DoOutgoingEmail()

	mockP1.ExpectOutMail(mail9)
	mockP2.ExpectOutMail(mail10)
	container.GetOutgoing() <- mail9
	mockP1.DoOutgoingEmail()
	container.GetOutgoing() <- mail10
	mockP2.DoOutgoingEmail()

}
Exemplo n.º 3
0
func GetProductionMTAContainer() (mtacontainer.MTAContainer, mtacontainer.Scheduler) {
	var passphrase = GetPassphraseFromArgOrTerminal()
	var mailGunConfig = mailgunprovider.BitLabConfig(passphrase)
	var amazonConfig = amazonsesprovider.BitLabConfig(passphrase)
	var sendgridConfig = sendgridprovider.BitLabConfig(passphrase)
	providers := make([]mtacontainer.MTAProvider, 3)
	providers[0] = mailgunprovider.New(utilities.GetLogger("MailGun"), mailGunConfig, mtacontainer.NewThressHoldFailureStrategy(ERROR_THRESHOLD))
	providers[1] = amazonsesprovider.New(utilities.GetLogger("amazonSES"), amazonConfig, mtacontainer.NewThressHoldFailureStrategy(ERROR_THRESHOLD))
	providers[2] = sendgridprovider.New(utilities.GetLogger("SendGrid"), sendgridConfig, mtacontainer.NewThressHoldFailureStrategy(ERROR_THRESHOLD))
	var scheduler mtacontainer.Scheduler = mtacontainer.NewRoundRobinScheduler(providers)
	return mtacontainer.New(scheduler), scheduler
}
func TestMTAProvider_allMock(t *testing.T) {

	var mockProvider = NewMockMTAProvider(t).(*MockMTAProvider)

	var s *SchedulerMock = NewSchedulerMock().(*SchedulerMock)
	s.SetProviders([]mtacontainer.MTAProvider{mockProvider})
	s.SetNextMTA(mockProvider)
	m := mtacontainer.New(s)

	mail := FreshTestMail(mockProvider, "*****@*****.**")

	mockProvider.ExpectOutMail(mail)
	m.GetOutgoing() <- mail

}
Exemplo n.º 5
0
func Test_all_failover(t *testing.T) {

	loop1 := loopbackprovider.New(utilities.GetLogger("loop1"), new(FailImmediatelyFailureStrategy))

	scheduler := mtacontainer.NewRoundRobinScheduler([]mtacontainer.MTAProvider{loop1})

	container := mtacontainer.New(scheduler)

	go func() {
		mail := FreshTestMail(loop1, "*****@*****.**")
		container.GetOutgoing() <- mail
		for {
			select {
			case evt := <-container.GetEvent():
				log.Println(evt.GetError().Error())
			}
		}
	}()

}
Exemplo n.º 6
0
func Test_one_failover(t *testing.T) {

	loop1 := loopbackprovider.New(utilities.GetLogger("loop1"), new(FailImmediatelyFailureStrategy))
	loop2 := loopbackprovider.New(utilities.GetLogger("loop2"), NewMockFailureStrategy())

	scheduler := mtacontainer.NewRoundRobinScheduler([]mtacontainer.MTAProvider{loop1, loop2})

	container := mtacontainer.New(scheduler)

	mail := FreshTestMail(loop1, "*****@*****.**")

	go func() {
		container.GetOutgoing() <- mail
		for {
			select {
			case evt := <-container.GetEvent():
				log.Println(evt.GetError().Error())
			}
		}
	}()

	// the round robin scheduler will schedule {loop1} which fails immediately
	// we expect to see {mail} emerge on the {GetIncoming} channel of {loop2}
	// because it has been RESUBMITTET to {loop2} by the fail over mechanism in
	// the MTAContainer.

	mailPrime, ok := <-loop2.GetIncoming()

	if ok == false {
		t.Error("loop2 incoming failed to provide emai.")
	}

	if mailPrime != mail {
		t.Error("Wrong mail")
	}
}
Exemplo n.º 7
0
func GetLoopBackContainer() (mtacontainer.MTAContainer, mtacontainer.Scheduler) {
	var provider = loopbackprovider.New(utilities.GetLogger("LoopBack"), mtacontainer.NewThressHoldFailureStrategy(ERROR_THRESHOLD))
	var scheduler = mtacontainer.NewRoundRobinScheduler([]mtacontainer.MTAProvider{provider})
	return mtacontainer.New(scheduler), scheduler
}