github.com/Jeffail/benthos/v3@v3.65.0/internal/impl/pulsar/integration_test.go (about)

     1  package pulsar
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/Jeffail/benthos/v3/internal/integration"
     9  	"github.com/apache/pulsar-client-go/pulsar"
    10  	"github.com/ory/dockertest/v3"
    11  	"github.com/stretchr/testify/assert"
    12  	"github.com/stretchr/testify/require"
    13  )
    14  
    15  func TestIntegrationPulsar(t *testing.T) {
    16  	integration.CheckSkip(t)
    17  	t.Parallel()
    18  
    19  	pool, err := dockertest.NewPool("")
    20  	require.NoError(t, err)
    21  
    22  	pool.MaxWait = time.Second * 30
    23  	if dline, exists := t.Deadline(); exists {
    24  		pool.MaxWait = time.Until(dline) / 2
    25  	}
    26  
    27  	resource, err := pool.Run("apachepulsar/pulsar-standalone", "latest", nil)
    28  	require.NoError(t, err)
    29  	t.Cleanup(func() {
    30  		assert.NoError(t, pool.Purge(resource))
    31  	})
    32  
    33  	resource.Expire(900)
    34  	require.NoError(t, pool.Retry(func() error {
    35  		client, err := pulsar.NewClient(pulsar.ClientOptions{
    36  			URL:    fmt.Sprintf("pulsar://localhost:%v/", resource.GetPort("6650/tcp")),
    37  			Logger: NoopLogger(),
    38  		})
    39  		if err != nil {
    40  			return err
    41  		}
    42  		prod, err := client.CreateProducer(pulsar.ProducerOptions{
    43  			Topic: "benthos-connection-test",
    44  		})
    45  		if err == nil {
    46  			prod.Close()
    47  		}
    48  		client.Close()
    49  		return err
    50  	}))
    51  
    52  	template := `
    53  output:
    54    pulsar:
    55      url: pulsar://localhost:$PORT/
    56      topic: "topic-$ID"
    57      max_in_flight: $MAX_IN_FLIGHT
    58  
    59  input:
    60    pulsar:
    61      url: pulsar://localhost:$PORT/
    62      topics: [ "topic-$ID" ]
    63      subscription_name: "sub-$ID"
    64  `
    65  	suite := integration.StreamTests(
    66  		integration.StreamTestOpenClose(),
    67  		integration.StreamTestSendBatch(10),
    68  		integration.StreamTestStreamSequential(1000),
    69  		integration.StreamTestStreamParallel(1000),
    70  		integration.StreamTestStreamParallelLossy(1000),
    71  		integration.StreamTestStreamParallelLossyThroughReconnect(1000),
    72  		integration.StreamTestAtLeastOnceDelivery(),
    73  	)
    74  	suite.Run(
    75  		t, template,
    76  		integration.StreamTestOptSleepAfterInput(500*time.Millisecond),
    77  		integration.StreamTestOptSleepAfterOutput(500*time.Millisecond),
    78  		integration.StreamTestOptPort(resource.GetPort("6650/tcp")),
    79  	)
    80  	t.Run("with max in flight", func(t *testing.T) {
    81  		t.Parallel()
    82  		suite.Run(
    83  			t, template,
    84  			integration.StreamTestOptSleepAfterInput(500*time.Millisecond),
    85  			integration.StreamTestOptSleepAfterOutput(500*time.Millisecond),
    86  			integration.StreamTestOptPort(resource.GetPort("6650/tcp")),
    87  			integration.StreamTestOptMaxInFlight(10),
    88  		)
    89  	})
    90  }