-func createNewRmrControl(desc string, rtfile string, port string, stat string) *testingRmrControl {
- os.Setenv("RMR_SEED_RT", rtfile)
- os.Setenv("RMR_SRC_ID", "localhost:"+port)
- xapp.Logger.Info("Using rt file %s", os.Getenv("RMR_SEED_RT"))
- xapp.Logger.Info("Using src id %s", os.Getenv("RMR_SRC_ID"))
- newConn := &testingRmrControl{}
- newConn.desc = desc
- newConn.syncChan = make(chan struct{})
- newConn.rmrClientTest = xapp.NewRMRClientWithParams("tcp:"+port, 4096, 1, stat)
- newConn.rmrConChan = make(chan *xapp.RMRParams)
- newConn.rmrClientTest.SetReadyCB(newConn.ReadyCB, nil)
- go newConn.rmrClientTest.Start(newConn)
- <-newConn.syncChan
- return newConn
+func initTestingRmrControl(desc string, rtfile string, port string, stat string, consumer xapp.MessageConsumer) testingRmrControl {
+ tc := testingRmrControl{}
+ tc.testingControl = initTestingControl(desc, rtfile, port)
+ tc.rmrClientTest = xapp.NewRMRClientWithParams("tcp:"+port, 4096, 1, stat)
+ tc.rmrClientTest.SetReadyCB(tc.ReadyCB, nil)
+ go tc.rmrClientTest.Start(consumer)
+ tc.WaitCB()
+ return tc
+}
+
+//-----------------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------------
+type testingMessageChannel struct {
+ rmrConChan chan *xapp.RMRParams
+}
+
+func initTestingMessageChannel() testingMessageChannel {
+ mc := testingMessageChannel{}
+ mc.rmrConChan = make(chan *xapp.RMRParams)
+ return mc
+}
+
+//-----------------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------------
+
+type testingXappControl struct {
+ testingRmrControl
+ testingMessageChannel
+ meid *xapp.RMRMeid
+ xid_seq uint64
+ xid string
+}
+
+func (tc *testingXappControl) newXid() string {
+ tc.xid = tc.desc + "_XID_" + strconv.FormatUint(uint64(tc.xid_seq), 10)
+ tc.xid_seq++
+ return tc.xid
+}
+
+func (tc *testingXappControl) Consume(msg *xapp.RMRParams) (err error) {
+
+ //if msg.Xid == tc.xid {
+ if strings.Contains(msg.Xid, tc.desc) {
+ xapp.Logger.Info("(%s) Consume mtype=%s subid=%d xid=%s", tc.desc, xapp.RicMessageTypeToName[msg.Mtype], msg.SubId, msg.Xid)
+ tc.rmrConChan <- msg
+ } else {
+ xapp.Logger.Info("(%s) Ignore mtype=%s subid=%d xid=%s, Expected xid to contain %s", tc.desc, xapp.RicMessageTypeToName[msg.Mtype], msg.SubId, msg.Xid, tc.desc)
+ }
+ return
+}
+
+func createNewXappControl(desc string, rtfile string, port string, stat string, ranname string) *testingXappControl {
+ xappCtrl := &testingXappControl{}
+ xappCtrl.testingRmrControl = initTestingRmrControl(desc, rtfile, port, stat, xappCtrl)
+ xappCtrl.testingMessageChannel = initTestingMessageChannel()
+ xappCtrl.meid = &xapp.RMRMeid{RanName: ranname}
+ xappCtrl.xid_seq = 0
+ xappCtrl.newXid()
+ return xappCtrl
+}
+
+//-----------------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------------
+type testingE2termControl struct {
+ testingRmrControl
+ testingMessageChannel
+}
+
+func (tc *testingE2termControl) Consume(msg *xapp.RMRParams) (err error) {
+ xapp.Logger.Info("(%s) Consume mtype=%s subid=%d xid=%s", tc.desc, xapp.RicMessageTypeToName[msg.Mtype], msg.SubId, msg.Xid)
+ tc.rmrConChan <- msg
+ return
+}
+
+func createNewE2termControl(desc string, rtfile string, port string, stat string) *testingE2termControl {
+ e2termCtrl := &testingE2termControl{}
+ e2termCtrl.testingRmrControl = initTestingRmrControl(desc, rtfile, port, stat, e2termCtrl)
+ e2termCtrl.testingMessageChannel = initTestingMessageChannel()
+ return e2termCtrl