github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/logtail/service/event_test.go (about)

     1  // Copyright 2021 Matrix Origin
     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 service
    16  
    17  import (
    18  	"context"
    19  	"testing"
    20  
    21  	"github.com/stretchr/testify/require"
    22  )
    23  
    24  func TestPublisher(t *testing.T) {
    25  	ctx, cancel := context.WithCancel(context.Background())
    26  	defer cancel()
    27  
    28  	event := NewNotifier(ctx, 10)
    29  	eventNum := 5
    30  
    31  	go func() {
    32  		for i := 1; i <= eventNum; i++ {
    33  			from, to := mockTimestamp(int64(i-1), 0), mockTimestamp(int64(i), 0)
    34  			table := mockTable(uint64(i), uint64(i), uint64(i))
    35  			err := event.NotifyLogtail(from, to, nil, mockLogtail(table, to))
    36  			require.NoError(t, err)
    37  		}
    38  	}()
    39  
    40  	for j := 1; j <= eventNum; j++ {
    41  		e := <-event.C
    42  		require.Equal(t, mockTimestamp(int64(j-1), 0), e.from)
    43  		require.Equal(t, mockTimestamp(int64(j), 0), e.to)
    44  		require.Equal(t, 1, len(e.logtails))
    45  	}
    46  }