github.com/braveheart12/just@v0.8.7/testutils/pulsarmodel/main.go (about)

     1  /*
     2   *    Copyright 2019 Insolar Technologies
     3   *
     4   *    Licensed under the Apache License, Version 2.0 (the "License");
     5   *    you may not use this file except in compliance with the License.
     6   *    You may obtain a copy of the License at
     7   *
     8   *        http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   *    Unless required by applicable law or agreed to in writing, software
    11   *    distributed under the License is distributed on an "AS IS" BASIS,
    12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   *    See the License for the specific language governing permissions and
    14   *    limitations under the License.
    15   */
    16  
    17  package main
    18  
    19  import (
    20  	"fmt"
    21  	"math/rand"
    22  )
    23  
    24  func main() {
    25  	rand.Seed(31)
    26  
    27  	fmt.Println("---------- Start to init -----------")
    28  	for networkNodeIndex := 0; networkNodeIndex < len(network); networkNodeIndex++ {
    29  		network[networkNodeIndex] = &NetworkNode{Neighbours: map[int]struct{}{}, PreviousSignals: map[int]struct{}{}}
    30  		network[networkNodeIndex].Channel = make(chan *Signal, 100000)
    31  		go network[networkNodeIndex].Listen(networkNodeIndex)
    32  	}
    33  	fmt.Println("---------- finish to init-----------")
    34  
    35  	fmt.Println("---------- Start to configure -----------")
    36  	for networkNodeIndex := 0; networkNodeIndex < len(network); networkNodeIndex++ {
    37  		for len(network[networkNodeIndex].Neighbours) < 300 {
    38  			nextEdge := rand.Intn(len(network))
    39  
    40  			_, ok := network[networkNodeIndex].Neighbours[nextEdge]
    41  			if !ok {
    42  				network[networkNodeIndex].Neighbours[nextEdge] = struct{}{}
    43  				network[nextEdge].Neighbours[nextEdge] = struct{}{}
    44  			}
    45  		}
    46  	}
    47  	fmt.Println("---------- finish to configure -----------")
    48  
    49  	pulse()
    50  	calculateLoad()
    51  }