func Test_NoReceiving_After_Unsubscribe(t *testing.T) { testutil.SkipIfDisabled(t) testutil.SkipIfShort(t) a := assert.New(t) node1 := newTestClusterNode(t, testClusterNodeConfig{ HttpListen: "localhost:8086", NodeID: 1, NodePort: 20006, Remotes: "localhost:20006", }) a.NotNil(node1) defer node1.cleanup(true) node2 := newTestClusterNode(t, testClusterNodeConfig{ HttpListen: "localhost:8087", NodeID: 2, NodePort: 20007, Remotes: "localhost:20006", }) a.NotNil(node2) defer node2.cleanup(true) node1.FCM.setupRoundTripper(20*time.Millisecond, 10, fcm.SuccessFCMResponse) node2.FCM.setupRoundTripper(20*time.Millisecond, 10, fcm.SuccessFCMResponse) // subscribe on first node node1.Subscribe(testTopic, "1") time.Sleep(50 * time.Millisecond) // connect a client and send a message client1, err := node1.client("user1", 1000, true) err = client1.Send(testTopic, "body", "{jsonHeader:1}") a.NoError(err) // only one message should be received but only on the first node. // Every message should be delivered only once. node1.FCM.checkReceived(1) node2.FCM.checkReceived(0) // Unsubscribe node2.Unsubscribe(testTopic, "1") time.Sleep(50 * time.Millisecond) // reset the counter node1.FCM.reset() // and send a message again. No one should receive it err = client1.Send(testTopic, "body", "{jsonHeader:1}") a.NoError(err) // only one message should be received but only on the second node. // Every message should be delivered only once. node1.FCM.checkReceived(0) node2.FCM.checkReceived(0) }
func TestNexmoSender_Send(t *testing.T) { a := assert.New(t) testutil.SkipIfDisabled(t) sender, err := NewNexmoSender(KEY, SECRET) a.NoError(err) sms := new(NexmoSms) sms.To = "+40746278186" sms.From = "REWE Lieferservice" sms.Text = "Lieber Kunde! Ihre Lieferung kommt heute zwischen 12.04 und 12.34 Uhr. Vielen Dank für Ihre Bestellung! Ihr REWE Lieferservice" response, err := sender.SendSms(sms) a.Equal(1, response.MessageCount) a.Equal(ResponseSuccess, response.Messages[0].Status) a.NoError(err) }
func TestRestMessageAPI_SetFiltersWhenServing(t *testing.T) { testutil.SkipIfDisabled(t) _, finish := testutil.NewMockCtrl(t) defer finish() a := assert.New(t) body := bytes.NewBufferString("") req, err := http.NewRequest( http.MethodPost, "http://localhost/test/message/topic?filterUserID=user01&filterDeviceID=ABC&filterDummyCamelCase=dummy_value", body) a.NoError(err) routerMock := NewMockRouter(testutil.MockCtrl) api := NewRestMessageAPI(routerMock, "/test/") recorder := httptest.NewRecorder() routerMock.EXPECT().HandleMessage(gomock.Any()).Do(func(msg *protocol.Message) error { a.NotNil(msg.Filters) if a.Contains(msg.Filters, "user_id") { a.Equal("user01", msg.Filters["user_id"]) } if a.Contains(msg.Filters, "device_id") { a.Equal("ABC", msg.Filters["device_id"]) } if a.Contains(msg.Filters, "dummy_camel_case") { a.Equal("dummy_value", msg.Filters["dummy_camel_case"]) } return nil }) api.ServeHTTP(recorder, req) time.Sleep(10 * time.Millisecond) }
func Test_Subscribe_working_After_Node_Restart(t *testing.T) { // defer testutil.EnableDebugForMethod()() testutil.SkipIfDisabled(t) testutil.SkipIfShort(t) a := assert.New(t) nodeConfig1 := testClusterNodeConfig{ HttpListen: "localhost:8082", NodeID: 1, NodePort: 20002, Remotes: "localhost:20002", } node1 := newTestClusterNode(t, nodeConfig1) a.NotNil(node1) node2 := newTestClusterNode(t, testClusterNodeConfig{ HttpListen: "localhost:8083", NodeID: 2, NodePort: 20003, Remotes: "localhost:20002", }) a.NotNil(node2) defer node2.cleanup(true) node1.FCM.setupRoundTripper(20*time.Millisecond, 10, fcm.SuccessFCMResponse) node2.FCM.setupRoundTripper(20*time.Millisecond, 10, fcm.SuccessFCMResponse) // subscribe on first node node1.Subscribe(testTopic, "1") // connect a clinet and send a message client1, err := node1.client("user1", 1000, true) a.NoError(err) err = client1.Send(testTopic, "body", "{jsonHeader:1}") a.NoError(err) // one message should be received but only on the first node. // Every message should be delivered only once. node1.FCM.checkReceived(1) node2.FCM.checkReceived(0) // stop a node, cleanup without removing directories node1.cleanup(false) time.Sleep(time.Millisecond * 150) // restart the service restartedNode1 := newTestClusterNode(t, nodeConfig1) a.NotNil(restartedNode1) defer restartedNode1.cleanup(true) restartedNode1.FCM.setupRoundTripper(20*time.Millisecond, 10, fcm.SuccessFCMResponse) // send a message to the former subscription. client1, err = restartedNode1.client("user1", 1000, true) a.NoError(err) time.Sleep(time.Second) err = client1.Send(testTopic, "body", "{jsonHeader:1}") a.NoError(err, "Subscription should work even after node restart") // only one message should be received but only on the first node. // Every message should be delivered only once. restartedNode1.FCM.checkReceived(1) node2.FCM.checkReceived(0) }
func TestThroughput(t *testing.T) { // TODO: We disabled this test because the receiver implementation of fetching messages // should be reimplemented according to the new message store testutil.SkipIfDisabled(t) testutil.SkipIfShort(t) defer testutil.ResetDefaultRegistryHealthCheck() dir, _ := ioutil.TempDir("", "guble_benchmarking_test") *Config.HttpListen = "localhost:0" *Config.KVS = "memory" *Config.MS = "file" *Config.StoragePath = dir service := StartService() testgroupCount := 4 messagesPerGroup := 100 log.Printf("init the %v testgroups", testgroupCount) testgroups := make([]*testgroup, testgroupCount, testgroupCount) for i := range testgroups { testgroups[i] = newTestgroup(t, i, service.WebServer().GetAddr(), messagesPerGroup) } // init test log.Print("init the testgroups") for i := range testgroups { testgroups[i].Init() } defer func() { // cleanup tests log.Print("cleanup the testgroups") for i := range testgroups { testgroups[i].Clean() } service.Stop() os.RemoveAll(dir) }() // start test log.Print("start the testgroups") start := time.Now() for i := range testgroups { go testgroups[i].Start() } log.Print("wait for finishing") for i, test := range testgroups { select { case successFlag := <-test.done: if !successFlag { t.Logf("testgroup %v returned with error", i) t.FailNow() return } case <-time.After(time.Second * 20): t.Log("timeout. testgroups not ready before timeout") t.Fail() return } } end := time.Now() totalMessages := testgroupCount * messagesPerGroup throughput := float64(totalMessages) / end.Sub(start).Seconds() log.Printf("finished! Throughput: %v/sec (%v message in %v)", int(throughput), totalMessages, end.Sub(start)) time.Sleep(time.Second * 1) }