go.temporal.io/server@v1.23.0/common/testing/generator_interface.go (about)

     1  // The MIT License
     2  //
     3  // Copyright (c) 2020 Temporal Technologies Inc.  All rights reserved.
     4  //
     5  // Copyright (c) 2020 Uber Technologies, Inc.
     6  //
     7  // Permission is hereby granted, free of charge, to any person obtaining a copy
     8  // of this software and associated documentation files (the "Software"), to deal
     9  // in the Software without restriction, including without limitation the rights
    10  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    11  // copies of the Software, and to permit persons to whom the Software is
    12  // furnished to do so, subject to the following conditions:
    13  //
    14  // The above copyright notice and this permission notice shall be included in
    15  // all copies or substantial portions of the Software.
    16  //
    17  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    18  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    19  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    20  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    21  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    22  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    23  // THE SOFTWARE.
    24  
    25  package testing
    26  
    27  type (
    28  	// Model represents a state transition graph that contains all the relationships of Vertex
    29  	Model interface {
    30  		AddEdge(...Edge)
    31  		ListEdges() []Edge
    32  	}
    33  
    34  	// Generator generates a sequence of vertices based on the defined models
    35  	// It must define InitialEntryVertex and ExitVertex
    36  	// To use a generator:
    37  	// for generator.HasNextVertex {
    38  	//     generator.GetNextVertices
    39  	// }
    40  	Generator interface {
    41  		// InitialEntryVertex is the beginning vertices of the graph
    42  		// Only one vertex will be picked as the entry
    43  		AddInitialEntryVertex(...Vertex)
    44  		// ExitVertex is the terminate vertices of the graph
    45  		AddExitVertex(...Vertex)
    46  		// RandomEntryVertex is a random entry point which can be access at any state of the generator
    47  		AddRandomEntryVertex(...Vertex)
    48  		// AddModel loads model into the generator
    49  		// AddModel can load multiple models and models will be joint if there is common vertices
    50  		AddModel(Model)
    51  		// HasNextVertex determines if there is more vertex to generate
    52  		HasNextVertex() bool
    53  		// GetNextVertices generates next vertex batch
    54  		GetNextVertices() []Vertex
    55  		// ListGeneratedVertices lists the pasted generated vertices
    56  		ListGeneratedVertices() []Vertex
    57  		// Reset cleans up all the internal states and reset to a brand new generator
    58  		Reset()
    59  		// DeepCopy copy a new instance of generator
    60  		DeepCopy() Generator
    61  		// SetBatchGenerationRule sets a function that used in GetNextVertex to return batch result
    62  		SetBatchGenerationRule(func([]Vertex, []Vertex) bool)
    63  		// SetVersion sets the event version
    64  		SetVersion(int64)
    65  		// GetVersion gets the event version
    66  		GetVersion() int64
    67  	}
    68  
    69  	// Vertex represents a state in the model. A state represents a type of an Temporal event
    70  	Vertex interface {
    71  		// The name of the vertex. Usually, this will be the Temporal event type
    72  		SetName(string)
    73  		GetName() string
    74  		//Equals(Vertex) bool
    75  		// IsStrictOnNextVertex means if the vertex must be followed by its children
    76  		// When IsStrictOnNextVertex set to true, it means this event can only follow by its neighbors
    77  		SetIsStrictOnNextVertex(bool)
    78  		IsStrictOnNextVertex() bool
    79  		// MaxNextVertex means the max neighbors can branch out from this vertex
    80  		SetMaxNextVertex(int)
    81  		GetMaxNextVertex() int
    82  
    83  		// SetVertexDataFunc sets a function to generate end vertex data
    84  		SetDataFunc(func(...interface{}) interface{})
    85  		GetDataFunc() func(...interface{}) interface{}
    86  		GenerateData(...interface{}) interface{}
    87  		GetData() interface{}
    88  		DeepCopy() Vertex
    89  	}
    90  
    91  	// Edge is the connection between two vertices
    92  	Edge interface {
    93  		// StartVertex is the head of the connection
    94  		SetStartVertex(Vertex)
    95  		GetStartVertex() Vertex
    96  		// EndVertex is the end of the connection
    97  		SetEndVertex(Vertex)
    98  		GetEndVertex() Vertex
    99  		// Condition defines a function to determine if this connection is accessible
   100  		SetCondition(func(...interface{}) bool)
   101  		GetCondition() func(...interface{}) bool
   102  		// Action defines function to perform when the end vertex reached
   103  		SetAction(func())
   104  		GetAction() func()
   105  		DeepCopy() Edge
   106  	}
   107  )