Skip to content

Commit

Permalink
reverted request backward on model.
Browse files Browse the repository at this point in the history
This is a breaking change that makes ranch compatible with transport. I want a better name, but this will have to do!

Also formatted code.

Signed-off-by: Dave Shanley <[email protected]>
  • Loading branch information
daveshanley committed Jul 31, 2023
1 parent a38cad6 commit 0c437b5
Show file tree
Hide file tree
Showing 53 changed files with 7,362 additions and 7,362 deletions.
418 changes: 209 additions & 209 deletions bridge/bridge_client.go

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions bridge/bridge_client_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,31 @@
package bridge

import (
"github.com/go-stomp/stomp/v3/frame"
"github.com/google/uuid"
"github.com/pb33f/ranch/model"
"sync"
"github.com/go-stomp/stomp/v3/frame"
"github.com/google/uuid"
"github.com/pb33f/ranch/model"
"sync"
)

// BridgeClientSub is a client subscription that encapsulates message and error channels for a subscription
type BridgeClientSub struct {
C chan *model.Message // MESSAGE payloads
E chan *model.Message // ERROR payloads.
Id *uuid.UUID
Destination string
Client *BridgeClient
subscribed bool
lock sync.RWMutex
C chan *model.Message // MESSAGE payloads
E chan *model.Message // ERROR payloads.
Id *uuid.UUID
Destination string
Client *BridgeClient
subscribed bool
lock sync.RWMutex
}

// Send an UNSUBSCRIBE frame for subscription destination.
func (cs *BridgeClientSub) Unsubscribe() {
cs.lock.Lock()
cs.subscribed = false
cs.lock.Unlock()
unsubscribeFrame := frame.New(frame.UNSUBSCRIBE,
frame.Id, cs.Id.String(),
frame.Destination, cs.Destination)
cs.lock.Lock()
cs.subscribed = false
cs.lock.Unlock()
unsubscribeFrame := frame.New(frame.UNSUBSCRIBE,
frame.Id, cs.Id.String(),
frame.Destination, cs.Destination)

cs.Client.SendFrame(unsubscribeFrame)
cs.Client.SendFrame(unsubscribeFrame)
}
70 changes: 35 additions & 35 deletions bridge/bridge_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,46 @@
package bridge

import (
"github.com/go-stomp/stomp/v3/frame"
"github.com/pb33f/ranch/model"
"github.com/stretchr/testify/assert"
"log"
"os"
"sync"
"testing"
"github.com/go-stomp/stomp/v3/frame"
"github.com/pb33f/ranch/model"
"github.com/stretchr/testify/assert"
"log"
"os"
"sync"
"testing"
)

func TestBridgeClient_Disconnect(t *testing.T) {

bc := new(BridgeClient)
e := bc.Disconnect()
assert.NotNil(t, e)
bc := new(BridgeClient)
e := bc.Disconnect()
assert.NotNil(t, e)
}

func TestBridgeClient_handleCommands(t *testing.T) {
d := "rainbow-land"
bc := new(BridgeClient)
i := make(chan *frame.Frame, 1)
e := make(chan *model.Message, 1)

l := log.New(os.Stderr, "WebSocket Client: ", 2)
bc.logger = l
bc.inboundChan = i
bc.Subscriptions = make(map[string]*BridgeClientSub)
s := &BridgeClientSub{E: e, Destination: d}
bc.Subscriptions[d] = s

go bc.handleIncomingSTOMPFrames()
wg := sync.WaitGroup{}

var sendError = func() {
f := frame.New(frame.ERROR, frame.Destination, d)
bc.inboundChan <- f
wg.Done()
}
wg.Add(1)
go sendError()
wg.Wait()
m := <-s.E
assert.Error(t, m.Error)
d := "rainbow-land"
bc := new(BridgeClient)
i := make(chan *frame.Frame, 1)
e := make(chan *model.Message, 1)

l := log.New(os.Stderr, "WebSocket Client: ", 2)
bc.logger = l
bc.inboundChan = i
bc.Subscriptions = make(map[string]*BridgeClientSub)
s := &BridgeClientSub{E: e, Destination: d}
bc.Subscriptions[d] = s

go bc.handleIncomingSTOMPFrames()
wg := sync.WaitGroup{}

var sendError = func() {
f := frame.New(frame.ERROR, frame.Destination, d)
bc.inboundChan <- f
wg.Done()
}
wg.Add(1)
go sendError()
wg.Wait()
m := <-s.E
assert.Error(t, m.Error)
}
2 changes: 1 addition & 1 deletion bridge/broker_connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func websocketHandler(w http.ResponseWriter, r *http.Request) {
}
}

//var srv Server
// var srv Server
var testBrokerAddress = ":51581"
var httpServer *httptest.Server
var tcpServer net.Listener
Expand Down
2 changes: 1 addition & 1 deletion bridge/broker_connector_tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
var webSocketURLChanTLS = make(chan string)
var websocketURLTLS string

//var srv Server
// var srv Server
var testTLS = &tls.Config{
InsecureSkipVerify: true,
MinVersion: tls.VersionTLS12,
Expand Down
Loading

0 comments on commit 0c437b5

Please sign in to comment.