github.com/lirm/aeron-go@v0.0.0-20230415210743-920325491dc4/systests/channel_validation_test.go (about)

     1  // Copyright 2022 Steven Stern
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  // http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package systests
    16  
    17  import (
    18  	"github.com/lirm/aeron-go/aeron"
    19  	"github.com/lirm/aeron-go/systests/driver"
    20  	"github.com/stretchr/testify/suite"
    21  	"testing"
    22  )
    23  
    24  type ChannelValidationTestSuite struct {
    25  	suite.Suite
    26  	mediaDriver *driver.MediaDriver
    27  	connection  *aeron.Aeron
    28  }
    29  
    30  func (suite *ChannelValidationTestSuite) SetupSuite() {
    31  	mediaDriver, err := driver.StartMediaDriver()
    32  	suite.Require().NoError(err, "Couldn't start Media Driver")
    33  	suite.mediaDriver = mediaDriver
    34  
    35  	connect, err := aeron.Connect(aeron.NewContext().AeronDir(suite.mediaDriver.TempDir))
    36  	if err != nil {
    37  		// Testify does not run TearDownSuite if SetupSuite fails.  We have to manually stop Media Driver.
    38  		suite.mediaDriver.StopMediaDriver()
    39  		suite.Require().NoError(err, "aeron couldn't connect")
    40  	}
    41  	suite.connection = connect
    42  }
    43  
    44  func (suite *ChannelValidationTestSuite) TearDownSuite() {
    45  	suite.connection.Close()
    46  	suite.mediaDriver.StopMediaDriver()
    47  }
    48  
    49  func (suite *ChannelValidationTestSuite) TestPublicationCantUseDifferentSoSndbufIfAlreadySetViaUri() {
    50  	pub1, err := suite.addPublication("aeron:udp?endpoint=localhost:9999|so-sndbuf=131072", 1000)
    51  	suite.Require().NoError(err)
    52  	defer pub1.Close()
    53  
    54  	pub2, err := suite.addPublication("aeron:udp?endpoint=localhost:9999|so-sndbuf=65536", 1001)
    55  	suite.Assert().Nil(pub2)
    56  	suite.Assert().Error(err)
    57  
    58  	pub3, err := suite.addPublication("aeron:udp?endpoint=localhost:9999|so-sndbuf=131072", 1002)
    59  	suite.Require().NoError(err)
    60  	defer pub3.Close()
    61  }
    62  
    63  func (suite *ChannelValidationTestSuite) TestSubscriptionCantUseDifferentSoSndbufIfAlreadySetViaUri() {
    64  	sub1, err := suite.addSubscription("aeron:udp?endpoint=localhost:9999|so-sndbuf=131072", 1000)
    65  	suite.Require().NoError(err)
    66  	defer sub1.Close()
    67  
    68  	sub2, err := suite.addSubscription("aeron:udp?endpoint=localhost:9999|so-sndbuf=65536", 1001)
    69  	suite.Assert().Nil(sub2)
    70  	suite.Assert().Error(err)
    71  
    72  	sub3, err := suite.addSubscription("aeron:udp?endpoint=localhost:9999|so-sndbuf=131072", 1002)
    73  	suite.Require().NoError(err)
    74  	defer sub3.Close()
    75  }
    76  
    77  func (suite *ChannelValidationTestSuite) addPublication(channel string, streamId int32) (*aeron.Publication, error) {
    78  	return suite.connection.AddPublication(channel, streamId)
    79  }
    80  
    81  func (suite *ChannelValidationTestSuite) addSubscription(channel string, streamId int32) (*aeron.Subscription, error) {
    82  	return suite.connection.AddSubscription(channel, streamId)
    83  }
    84  
    85  func TestChannelValidation(t *testing.T) {
    86  	suite.Run(t, new(ChannelValidationTestSuite))
    87  }