コード例 #1
0
ファイル: service_test.go プロジェクト: cyanly/gotrade
func TestServiceStartAndStop(t *testing.T) {
	ts := test.RunDefaultServer()
	defer ts.Shutdown()

	sc := NewConfig()
	sc.ServiceName = "Test Service"
	sc.MessageBusURL = "nats://localhost:22222"

	svc := NewService(sc)
	if svc.Status != proto.STARTING {
		t.Fatalf("unexpected service status: %s , expecting STARTING", svc.Status)
	}

	svc.Start()
	if svc.Status != proto.RUNNING {
		t.Fatalf("unexpected service status: %s, expecting RUNNING", svc.Status)
	}

	time.Sleep(500 * time.Millisecond)
	svc.shutdownChannel <- true
	time.Sleep(100 * time.Millisecond)

	if svc.Status != proto.STOPPED {
		t.Fatalf("unexpected service status: %s, expecting STOPPED", svc.Status)
	}
}
コード例 #2
0
ファイル: orderrouter_test.go プロジェクト: cyanly/gotrade
func TestMain(m *testing.M) {
	//mock message bus
	ts := test.RunDefaultServer()
	defer ts.Shutdown()

	code := m.Run()
	os.Exit(code)
}
コード例 #3
0
ファイル: simulator_test.go プロジェクト: cyanly/gotrade
func TestMain(m *testing.M) {
	//mock message bus
	ts := test.RunDefaultServer()
	defer ts.Shutdown()

	//simulate a sell side FIX server
	sellsvc := sellsidesim.NewSellSideSimulator("")
	sellsvc.Start()
	defer sellsvc.Close()

	code := m.Run()
	os.Exit(code)
}
コード例 #4
0
ファイル: client2fix_test.go プロジェクト: cyanly/gotrade
func TestMain(m *testing.M) {
	// Start a temporary messaging broker
	ts := test.RunDefaultServer()
	defer ts.Shutdown()

	// Start OrderRouter service
	orSC := orderrouter.NewConfig()
	orSC.MessageBusURL = "nats://localhost:22222"
	orSC.ServiceMessageBusURL = "nats://localhost:22222"
	orSC.DatabaseDriver = "memstore"
	orSvc := orderrouter.NewOrderRouter(orSC)
	orSvc.Start()
	defer orSvc.Close()

	// Start Simulated FIX Sell Side
	sellsvc := sellsidesim.NewSellSideSimulator("")
	sellsvc.Start()
	defer sellsvc.Close()

	// Start a MarketConnector Service for simuilated market
	// 1. MC (implementation)
	mcSC := MCCommon.NewConfig()
	mcSC.MessageBusURL = "nats://localhost:22222"
	mcSC.DatabaseDriver = "memstore"
	mcSvc := MCSimulator.NewMarketConnector(mcSC)
	mcSvc.Start()
	defer mcSvc.Close()
	// 2. Service (heartbeating etc)
	sc := service.NewConfig()
	sc.MessageBusURL = "nats://localhost:22222"
	sc.ServiceName = "MC." + mcSvc.Name()
	svc := service.NewService(sc)
	svc.Start()
	defer svc.Stop()

	// Turn off logging to measure performance
	logger.Discard()

	time.Sleep(100 * time.Millisecond) // async

	// Connect messaging bus for this mock client
	if nc, err := nats.Connect("nats://localhost:22222"); err != nil {
		log.Fatal("error: Cannot connect to message bus")
	} else {
		msgbus = nc
	}

	code := m.Run()
	os.Exit(code)
}