-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kryvchun
committed
Dec 26, 2022
1 parent
d31eb03
commit 2367a15
Showing
18 changed files
with
1,104 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea/* | ||
.idea/**/* | ||
.idea | ||
.idea | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
version: "3" | ||
|
||
# This file is used for testing the library. | ||
# | ||
# Running tests in docker: | ||
# docker-compose run --rm test | ||
# | ||
# Running tests locally: | ||
# export TEST_SONIC_ADDR="sonic://:[email protected]:1491" | ||
# docker-compose up -d sonic | ||
# go test ./... | ||
# | ||
# Cleanup: | ||
# docker-compose down | ||
|
||
services: | ||
sonic: | ||
build: | ||
context: ./testdata | ||
volumes: | ||
- ./testdata/sonic.cfg:/etc/sonic.cfg:ro | ||
ports: | ||
- "127.0.0.1:1491:1491" | ||
environment: | ||
RUST_BACKTRACE: "full" | ||
healthcheck: | ||
test: nc -z 127.0.0.1 1491 | ||
interval: 5s | ||
timeout: 3s | ||
retries: 7 | ||
|
||
test: | ||
image: "golang:1.18.3" | ||
depends_on: | ||
sonic: | ||
condition: service_healthy | ||
volumes: | ||
- .:/app:ro | ||
environment: | ||
- TEST_SONIC_ADDR=sonic://:SecretPassword@sonic:1491 | ||
command: bash -c "cd /app && go test ./..." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package sonic | ||
|
||
// driversHolder defines base interface around driversPool. | ||
type driversHolder struct { | ||
*driversPool | ||
} | ||
|
||
func newDriversHolder( | ||
opts controllerOptions, | ||
) (*driversHolder, error) { | ||
df := driverFactory{ | ||
Host: opts.Host, | ||
Port: opts.Port, | ||
Password: opts.Password, | ||
Channel: opts.Channel, | ||
} | ||
|
||
dp, err := newDriversPool( | ||
&df, | ||
opts.PoolMinConnections, | ||
opts.PoolMaxConnections, | ||
opts.PoolPingThreshold, | ||
opts.PoolMaxIdleLifetime, | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &driversHolder{ | ||
driversPool: dp, | ||
}, nil | ||
} | ||
|
||
// Quit all connections and close the pool. It never returns an error. | ||
func (c *driversHolder) Quit() error { | ||
c.driversPool.Close() | ||
|
||
return nil | ||
} | ||
|
||
// Ping one connection. | ||
func (c *driversHolder) Ping() error { | ||
d, err := c.Get() | ||
if err != nil { | ||
return err | ||
} | ||
defer d.close() | ||
|
||
return d.Ping() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package sonic_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/expectedsh/go-sonic/sonic" | ||
) | ||
|
||
func TestController(t *testing.T) { | ||
t.Parallel() | ||
|
||
var ctrl sonic.Base = getIngester(t) | ||
|
||
err := ctrl.Ping() | ||
if err != nil { | ||
t.Fatal("Ping", err) | ||
} | ||
|
||
err = ctrl.Quit() | ||
if err != nil { | ||
t.Fatal("Quit", err) | ||
} | ||
|
||
err = ctrl.Ping() | ||
if err == nil { | ||
t.Fatal("Ping", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.