vitess.io/vitess@v0.16.2/go/vt/vttablet/tabletmanager/vreplication/queryhistory/sequenced_expectation.go (about)

     1  package queryhistory
     2  
     3  // SequencedExpectation is an Expectation situated in an ExpectationSequence.
     4  // In other words, it is an Expectation with temporal relationships to other
     5  // Expectations.
     6  type SequencedExpectation interface {
     7  	Expectation
     8  
     9  	// EventuallyAfter returns the SequencedExpectationSet containing
    10  	// SequencedExpectations which this SequencedExpectation eventually
    11  	// follows.
    12  	EventuallyAfter() SequencedExpectationSet
    13  	// EventuallyBefore returns the SequencedExpectationSet contains
    14  	// SequencedExpectations eventually follow this SequencedExpectation.
    15  	EventuallyBefore() SequencedExpectationSet
    16  	// ExpectImmediatelyAfter sets the SequencedExpectation which this
    17  	// SequencedExpectation immediately follows. It also sets the inverse
    18  	// relationship on the provided expectation.
    19  	ExpectImmediatelyAfter(SequencedExpectation)
    20  	// ExpectImmediatelyBefore sets the SequencedExpectation which immediately
    21  	// follow this SequencedExpectation. It also sets the inverse relationship
    22  	// on the provided expectation.
    23  	ExpectImmediatelyBefore(SequencedExpectation)
    24  	// ExpectEventuallyAfter adds a SequencedExpectation to the
    25  	// SequencedExpectationSet which this SequencedExpectation eventually
    26  	// follows. It also sets the inverse relationship on the provided
    27  	// expectation.
    28  	ExpectEventuallyAfter(SequencedExpectation)
    29  	// ExpectEventuallyAfter adds a SequencedExpectation to the
    30  	// SequencedExpectationSet which eventually follows this
    31  	// SequencedExpectation. It also sets the inverse relationship on the
    32  	// provided expectation.
    33  	ExpectEventuallyBefore(SequencedExpectation)
    34  	// ImmediatelyAfter returns the SequencedExpectation which this
    35  	// SequencedExpectation immediately follows.
    36  	ImmediatelyAfter() SequencedExpectation
    37  	// ImmediatelyBefore returns the SequencedExpectation which immediately
    38  	// follows this SequencedExpectation.
    39  	ImmediatelyBefore() SequencedExpectation
    40  }
    41  
    42  type sequencedExpectation struct {
    43  	Expectation
    44  	eventuallyAfter   SequencedExpectationSet
    45  	eventuallyBefore  SequencedExpectationSet
    46  	immediatelyAfter  SequencedExpectation
    47  	immediatelyBefore SequencedExpectation
    48  }
    49  
    50  func newSequencedExpectation(expectation Expectation) SequencedExpectation {
    51  	eventuallyAfter := sequencedExpectationSet(make(map[SequencedExpectation]any))
    52  	eventuallyBefore := sequencedExpectationSet(make(map[SequencedExpectation]any))
    53  	return &sequencedExpectation{
    54  		Expectation:      expectation,
    55  		eventuallyAfter:  &eventuallyAfter,
    56  		eventuallyBefore: &eventuallyBefore,
    57  	}
    58  }
    59  
    60  func (se *sequencedExpectation) EventuallyAfter() SequencedExpectationSet {
    61  	return se.eventuallyAfter
    62  }
    63  
    64  func (se *sequencedExpectation) EventuallyBefore() SequencedExpectationSet {
    65  	return se.eventuallyBefore
    66  }
    67  
    68  func (se *sequencedExpectation) ExpectEventuallyAfter(expectation SequencedExpectation) {
    69  	if !se.eventuallyAfter.Contains(expectation) {
    70  		se.eventuallyAfter.Add(expectation)
    71  		expectation.ExpectEventuallyBefore(se)
    72  	}
    73  }
    74  
    75  func (se *sequencedExpectation) ExpectEventuallyBefore(expectation SequencedExpectation) {
    76  	if !se.eventuallyBefore.Contains(expectation) {
    77  		se.eventuallyBefore.Add(expectation)
    78  		expectation.ExpectEventuallyAfter(se)
    79  	}
    80  }
    81  
    82  func (se *sequencedExpectation) ExpectImmediatelyAfter(expectation SequencedExpectation) {
    83  	if se.immediatelyAfter != expectation {
    84  		se.immediatelyAfter = expectation
    85  		expectation.ExpectImmediatelyBefore(se)
    86  	}
    87  }
    88  
    89  func (se *sequencedExpectation) ExpectImmediatelyBefore(expectation SequencedExpectation) {
    90  	if se.immediatelyBefore != expectation {
    91  		se.immediatelyBefore = expectation
    92  		expectation.ExpectImmediatelyAfter(se)
    93  	}
    94  }
    95  
    96  func (se *sequencedExpectation) ImmediatelyAfter() SequencedExpectation {
    97  	return se.immediatelyAfter
    98  }
    99  
   100  func (se *sequencedExpectation) ImmediatelyBefore() SequencedExpectation {
   101  	return se.immediatelyBefore
   102  }