-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new command 'conn' to perform connection relation actions added.
Currently server side closing of connections is supported. Use `rabtap info --consumer` to find the name of the connection to close, then `rabtap close <connection-name>' to close the connection. See READNE.md for details.
- Loading branch information
1 parent
915c005
commit 4dbc7d5
Showing
14 changed files
with
298 additions
and
17 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,13 +1,18 @@ | ||
# Changelog | ||
# Changelog for rabtap | ||
|
||
## [unreleased] | ||
## v1.8 (2018-05-06) | ||
|
||
### Added | ||
* `--consumers` option of the `info` command now prints also information on | ||
|
||
* a changelog ;) | ||
* new `--consumers` option of the `info` command prints also information on | ||
the connection. | ||
* new command `conn` for connection related operations. Currently allows | ||
to close a connection with `rabtap conn close <connection-name>`. | ||
|
||
### Changed | ||
* minor changes to output of `info` command (i.e. some values now are quoted) | ||
|
||
* minor changes to output of `info` command (i.e. some values are now quoted) | ||
|
||
|
||
|
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,16 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/tls" | ||
"fmt" | ||
"os" | ||
|
||
rabtap "github.com/jandelgado/rabtap/pkg" | ||
) | ||
|
||
func cmdConnClose(apiURI, connName, reason string, tlsConfig *tls.Config) error { | ||
client := rabtap.NewRabbitHTTPClient(apiURI, tlsConfig) | ||
err := client.CloseConnection(connName, reason) | ||
failOnError(err, fmt.Sprintf("close connection '%s'", connName), os.Exit) | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright (C) 2017 Jan Delgado | ||
// +build integration | ||
|
||
package main | ||
|
||
import ( | ||
"crypto/tls" | ||
"testing" | ||
"time" | ||
|
||
rabtap "github.com/jandelgado/rabtap/pkg" | ||
"github.com/jandelgado/rabtap/pkg/testcommon" | ||
"github.com/streadway/amqp" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func findClosedConnName(connectionsBefore []rabtap.RabbitConnection, | ||
connectionsAfter []rabtap.RabbitConnection) string { | ||
// given to lists of connections, find the first connection by name which | ||
// is in the first, but not in the second list. | ||
for _, ca := range connectionsAfter { | ||
found := false | ||
for _, cb := range connectionsBefore { | ||
if ca.Name == cb.Name { | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
return ca.Name | ||
} | ||
} | ||
return "" | ||
} | ||
|
||
func TestCmdCloseConnection(t *testing.T) { | ||
|
||
uri := testcommon.IntegrationAPIURIFromEnv() | ||
client := rabtap.NewRabbitHTTPClient(uri, &tls.Config{}) | ||
|
||
// we can not get the name of a connection through the API of the AMQP client. So | ||
// we figure out the connections name by comparing the list of active | ||
// connection before and after we created our test connection. Therefore, | ||
// make sure this test runs isolated on the broker. | ||
connsBefore, err := client.Connections() | ||
require.Nil(t, err) | ||
|
||
// start the test connection to be terminated | ||
conn, _ := testcommon.IntegrationTestConnection(t, "", "", 0, false) | ||
|
||
// it takes a few seconds for the new connection to show up in the REST API | ||
time.Sleep(time.Second * 5) | ||
|
||
connsAfter, err := client.Connections() | ||
require.Nil(t, err) | ||
|
||
// we add a notification callback and expect the cb to be called | ||
// when we close the connection via the API | ||
errorChan := make(chan *amqp.Error) | ||
conn.NotifyClose(errorChan) | ||
|
||
connToClose := findClosedConnName(connsBefore, connsAfter) | ||
require.NotEqual(t, "", connToClose) | ||
|
||
// now close the newly created connection. TODO handle potential | ||
// call to failOnError in cmdConnClose | ||
err = cmdConnClose(uri, connToClose, "some reason", &tls.Config{}) | ||
require.Nil(t, err) | ||
|
||
// ... and make sure it gets closed, notified by a message on the errorChan | ||
connClosed := false | ||
select { | ||
case <-errorChan: | ||
connClosed = true | ||
case <-time.After(time.Second * 2): | ||
assert.Fail(t, "did not receive notification within expected time") | ||
} | ||
assert.True(t, connClosed) | ||
} |
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.