mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-24 13:48:49 +08:00

* Replace Nats with Nats Jestream For PubSub Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Add Stream Description Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Fix connection leak in NATS publisher The publisher struct in pkg/messaging/nats/publisher.go was modified to include a new `conn` field of type `*broker.Conn`. This change was made to fix a connection leak issue in the NATS publisher. The `NewPublisher` function was updated to assign the `conn` parameter to the new `conn` field in the publisher struct. Additionally, the `Close` method in the publisher struct was modified to close the `conn` connection. This commit fixes the connection leak issue in the NATS publisher and ensures that connections are properly closed. Signed-off-by: Rodney Osodo <socials@rodneyosodo.com> * Setup subscriber config to contain handler topic and ID Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Add delivery policy Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Avoid duplicate messages Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Rename to DeliveryPolicy Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Fix tests Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Not check for data result set when we are returning subset of messages Signed-off-by: Rodney Osodo <socials@rodneyosodo.com> Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * For unsubscribe remove config Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * Fix comment Signed-off-by: rodneyosodo <blackd0t@protonmail.com> --------- Signed-off-by: rodneyosodo <blackd0t@protonmail.com> Signed-off-by: Rodney Osodo <socials@rodneyosodo.com> Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
76 lines
1.7 KiB
Go
76 lines
1.7 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package cassandra_test
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/gocql/gocql"
|
|
casclient "github.com/mainflux/mainflux/internal/clients/cassandra"
|
|
mflog "github.com/mainflux/mainflux/logger"
|
|
"github.com/ory/dockertest/v3"
|
|
)
|
|
|
|
var logger, _ = mflog.New(os.Stdout, mflog.Info.String())
|
|
|
|
func TestMain(m *testing.M) {
|
|
pool, err := dockertest.NewPool("")
|
|
if err != nil {
|
|
logger.Error(fmt.Sprintf("Could not connect to docker: %s", err))
|
|
}
|
|
|
|
container, err := pool.Run("cassandra", "3.11.10", []string{})
|
|
if err != nil {
|
|
logger.Error(fmt.Sprintf("Could not start container: %s", err))
|
|
}
|
|
|
|
port := container.GetPort("9042/tcp")
|
|
addr = fmt.Sprintf("%s:%s", addr, port)
|
|
|
|
if err = pool.Retry(func() error {
|
|
if err := createKeyspace([]string{addr}); err != nil {
|
|
return err
|
|
}
|
|
|
|
session, err := casclient.Connect(casclient.Config{
|
|
Hosts: []string{addr},
|
|
Keyspace: keyspace,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer session.Close()
|
|
|
|
return nil
|
|
}); err != nil {
|
|
logger.Fatal(fmt.Sprintf("Could not connect to docker: %s", err))
|
|
}
|
|
|
|
code := m.Run()
|
|
|
|
if err := pool.Purge(container); err != nil {
|
|
logger.Error(fmt.Sprintf("Could not purge container: %s", err))
|
|
}
|
|
|
|
os.Exit(code)
|
|
}
|
|
|
|
func createKeyspace(hosts []string) error {
|
|
cluster := gocql.NewCluster(hosts...)
|
|
cluster.Consistency = gocql.Quorum
|
|
|
|
session, err := cluster.CreateSession()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer session.Close()
|
|
|
|
keyspaceCQL := fmt.Sprintf(`CREATE KEYSPACE IF NOT EXISTS %s WITH replication =
|
|
{'class':'SimpleStrategy','replication_factor':'1'}`, keyspace)
|
|
|
|
return session.Query(keyspaceCQL).Exec()
|
|
}
|