github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/logtail/service/waterline_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  	"testing"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/pb/timestamp"
    21  	"github.com/stretchr/testify/require"
    22  )
    23  
    24  func TestWaterliner(t *testing.T) {
    25  	current := mockTimestamp(100, 100)
    26  
    27  	w := NewWaterliner()
    28  
    29  	/* ---- waterline not initialized ---- */
    30  	waterline := w.Waterline()
    31  	require.Equal(t, timestamp.Timestamp{}, waterline)
    32  
    33  	/* ---- advance waterline ---- */
    34  	w.Advance(current)
    35  	waterline = w.Waterline()
    36  	require.Equal(t, current, waterline)
    37  
    38  	/* ---- advance with a backward ts ---- */
    39  	require.Panics(t, func() {
    40  		prev := current.Prev()
    41  		w.Advance(prev)
    42  	})
    43  
    44  	/* ---- advance with a monotonous ts ---- */
    45  	next := current.Next()
    46  	w.Advance(next)
    47  	waterline = w.Waterline()
    48  	require.Equal(t, next, waterline)
    49  }