github.com/leonlxy/hyperledger@v1.0.0-alpha.0.20170427033203-34922035d248/bddtests/regression/go/ote/ote_test.go (about)

     1  /*
     2  Copyright IBM Corp. 2017 All Rights Reserved.
     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        // Orderer Test Engine
    18  
    19  import (
    20          "fmt"
    21          "testing"
    22          "time"
    23          "strconv"
    24  )
    25  
    26  // simplest testcase
    27  func Test_1tx_1ch_1ord_Solo(t *testing.T) {
    28          fmt.Println("\nSimplest test: Send 1 TX on 1 channel to 1 Solo orderer")
    29          passResult, finalResultSummaryString := ote("Test_1tx_1ch_1ord_Solo", 1, 1, 1, "solo", 0, false, 1 )
    30          t.Log(finalResultSummaryString)
    31          if !passResult { t.Fail() }
    32  }
    33  
    34  // 76 - moved below
    35  
    36  // 77, 78 = rerun with batchsize = 500 // CONFIGTX_ORDERER_BATCHSIZE_MAXMESSAGECOUNT=500
    37  func Test_ORD77_ORD78_10000TX_1ch_1ord_solo_batchSz(t *testing.T) {
    38          //fmt.Println("Send 10,000 TX on 1 channel to 1 Solo orderer")
    39          passResult, finalResultSummaryString := ote("ORD-77_ORD-78", 10000, 1, 1, "solo", 0, false, 1 )
    40          if !passResult { t.Error(finalResultSummaryString) }
    41  }
    42  
    43  // 79, 80 = rerun with batchsize = 500
    44  func Test_ORD79_ORD80_10000TX_1ch_1ord_kafka_1kbs_batchSz(t *testing.T) {
    45          passResult, finalResultSummaryString := ote("ORD-79,ORD-80", 10000, 1, 1, "kafka", 1, false, 1 )
    46          if !passResult { t.Error(finalResultSummaryString) }
    47  }
    48  
    49  // 81, 82 = rerun with batchsize = 500
    50  func Test_ORD81_ORD82_10000TX_3ch_1ord_kafka_3kbs_batchSz(t *testing.T) {
    51          passResult, finalResultSummaryString := ote("ORD-81,ORD-82", 10000, 3, 1, "kafka", 3, false, 1 )
    52          if !passResult { t.Error(finalResultSummaryString) }
    53  }
    54  
    55  // 83, 84 = rerun with batchsize = 500
    56  func Test_ORD83_ORD84_10000TX_3ch_3ord_kafka_3kbs_batchSz(t *testing.T) {
    57          passResult, finalResultSummaryString := ote("ORD-83,ORD-84", 10000, 3, 3, "kafka", 3, false, 1 )
    58          if !passResult { t.Error(finalResultSummaryString) }
    59  }
    60  
    61  // 85
    62  func Test_ORD85_1000000TX_1ch_3ord_kafka_3kbs_spy(t *testing.T) {
    63          passResult, finalResultSummaryString := ote("ORD-85", 1000000, 1, 3, "kafka", 3, true, 1 )
    64          if !passResult { t.Error(finalResultSummaryString) }
    65  }
    66  
    67  // 86
    68  func Test_ORD86_1000000TX_3ch_1ord_kafka_3kbs_spy(t *testing.T) {
    69          passResult, finalResultSummaryString := ote("ORD-86", 1000000, 1, 1, "kafka", 3, true, 1 )
    70          if !passResult { t.Error(finalResultSummaryString) }
    71  }
    72  
    73  // 87
    74  func Test_ORD87_1000000TX_3ch_3ord_kafka_3kbs_spy(t *testing.T) {
    75          passResult, finalResultSummaryString := ote("ORD-87", 1000000, 3, 3, "kafka", 3, true, 1 )
    76          if !passResult { t.Error(finalResultSummaryString) }
    77  }
    78  
    79  /* The "3 producers" option is not supported, so no need to run these tests yet
    80  // 88
    81  func Test_ORD88_1000000TX_1ch_1ord_kafka_3kbs_spy_3ppc(t *testing.T) {
    82          passResult, finalResultSummaryString := ote("ORD-88", 1000000, 1, 1, "kafka", 3, true, 3 )
    83          if !passResult { t.Error(finalResultSummaryString) }
    84  }
    85  
    86  // 89
    87  func Test_ORD89_1000000TX_3ch_3ord_kafka_3kbs_spy_3ppc(t *testing.T) {
    88          passResult, finalResultSummaryString := ote("ORD-89", 1000000, 3, 3, "kafka", 3, true, 3 )
    89          if !passResult { t.Error(finalResultSummaryString) }
    90  }
    91  */
    92  
    93  // 90
    94  func Test_ORD90_1000000TX_100ch_1ord_kafka_3kbs_spy(t *testing.T) {
    95          passResult, finalResultSummaryString := ote("ORD-90", 1000000, 100, 1, "kafka", 3, true, 1 )
    96          if !passResult { t.Error(finalResultSummaryString) }
    97  }
    98  
    99  // 91
   100  func Test_ORD91_1000000TX_100ch_3ord_kafka_3kbs(t *testing.T) {
   101          passResult, finalResultSummaryString := ote("ORD-91", 1000000, 100, 3, "kafka", 3, true, 1 )
   102          if !passResult { t.Error(finalResultSummaryString) }
   103  }
   104  
   105  func pauseAndUnpause(target string) {
   106          time.Sleep(40 * time.Second)
   107          executeCmd("docker pause " + target + "; sleep 30; docker unpause " + target + " ")
   108  }
   109  
   110  func stopAndStart(target string) {
   111          time.Sleep(40 * time.Second)
   112          executeCmd("docker stop " + target + "; sleep 30; docker start " + target)
   113  }
   114  
   115  func stopAndStartAllTargetOneAtATime(target string, num int) {
   116          fmt.Println("Stop and Start ", num, " " + target + "s sequentially")
   117          for i := 0 ; i < num ; i++ {
   118                  stopAndStart(target + strconv.Itoa(i))
   119          }
   120          // A restart (below) is similar, but lacks delays in between
   121          // executeCmd("docker restart kafka0 kafka1 kafka2")
   122          fmt.Println("All ", num, " requested " + target + "s are stopped and started")
   123  }
   124  
   125  func pauseAndUnpauseAllTargetOneAtATime(target string, num int) {
   126          fmt.Println("Pause and Unpause ", num, " " + target + "s sequentially")
   127          for i := 0 ; i < num ; i++ {
   128                  pauseAndUnpause(target + strconv.Itoa(i))
   129          }
   130          fmt.Println("All ", num, " requested " + target + "s are paused and unpaused")
   131  }
   132  
   133  // 76
   134  func Test_ORD76_40000TX_1ch_1ord_kafka_3kbs(t *testing.T) {
   135          go stopAndStart("kafka0")
   136          passResult, finalResultSummaryString := ote("ORD-76", 100000, 1, 1, "kafka", 3, false, 1 )
   137          if !passResult { t.Error(finalResultSummaryString) }
   138  }
   139  
   140  // 92 and 93 - orderer tests, moved below
   141  
   142  //94 - stopAndStartAll KafkaBrokers OneAtATime
   143  func Test_ORD94_500000TX_1ch_3ord_kafka_3kbs(t *testing.T) {
   144          go stopAndStartAllTargetOneAtATime("kafka", 3)
   145          passResult, finalResultSummaryString := ote("ORD-94", 500000, 1, 3, "kafka", 3, false, 1 )
   146          if !passResult { t.Error(finalResultSummaryString) }
   147  }
   148  
   149  //95 - pauseAndUnpauseAll KafkaBrokers OneAtATime
   150  func Test_ORD95_500000TX_1ch_3ord_kafka_3kbs(t *testing.T) {
   151          go pauseAndUnpauseAllTargetOneAtATime("kafka", 3)
   152          passResult, finalResultSummaryString := ote("ORD-95", 500000, 1, 3, "kafka", 3, false, 1 )
   153          if !passResult { t.Error(finalResultSummaryString) }
   154  }
   155  
   156  //96 - stopping n-1 KBs
   157  func Test_ORD96_500000TX_1ch_3ord_kafka_3kbs(t *testing.T) {
   158          go kafka_3kb_restart_2kb_delay()
   159          passResult, finalResultSummaryString := ote("ORD-96", 500000, 1, 3, "kafka", 3, false, 1 )
   160          if !passResult { t.Error(finalResultSummaryString) }
   161  }
   162  func kafka_3kb_restart_2kb_delay() {
   163          time.Sleep(40 * time.Second)
   164          fmt.Println("Stopping 2 of 3 Kafka brokers")
   165          executeCmd("docker stop kafka0 ; sleep 30 ; docker stop kafka1 ; sleep 30 ; docker start kafka1 ; docker start kafka0")
   166          fmt.Println("kafka brokers are restarted")
   167  }
   168  
   169  //97 - stopping all the kafka brokers at once
   170  func Test_ORD97_500000TX_1ch_3ord_kafka_3kbs(t *testing.T) {
   171          go kafka_3kb_restart_3kb()
   172          passResult, finalResultSummaryString := ote("ORD-96", 500000, 1, 3, "kafka", 3, false, 1 )
   173          if !passResult { t.Error(finalResultSummaryString) }
   174  }
   175  func kafka_3kb_restart_3kb() {
   176          time.Sleep(40 * time.Second)
   177          fmt.Println("Stopping the Kafka brokers")
   178          executeCmd("docker stop kafka0 kafka1 kafka2 ; sleep 30 ; docker start kafka0 kafka1 kafka2")
   179          fmt.Println("All the kafka brokers are restarted")
   180  }
   181  
   182  //98 - pausing n-1 KBs
   183  func Test_ORD98_500000TX_1ch_3ord_kafka_3kbs(t *testing.T) {
   184          go kafka_3kb_pause_2kb_delay()
   185          passResult, finalResultSummaryString := ote("ORD-97", 500000, 1, 3, "kafka", 3, false, 1 )
   186          if !passResult { t.Error(finalResultSummaryString) }
   187  }
   188  func kafka_3kb_pause_2kb_delay() {
   189          time.Sleep(40 * time.Second)
   190          fmt.Println("Pausing the Kafka brokers")
   191          executeCmd("docker pause kafka0 ; sleep 30 ; docker pause kafka1 ; sleep 30 ; docker unpause kafka1 ; docker unpause kafka0")
   192          fmt.Println("All the kafka brokers are restarted")
   193  }
   194  
   195  //99 pausing all the kafka brokers at once
   196  func Test_ORD99_500000TX_1ch_3ord_kafka_3kbs(t *testing.T) {
   197         go kafka_3kb_pause_3kb()
   198         passResult, finalResultSummaryString := ote("ORD-97", 500000, 1, 3, "kafka", 3, false, 1 )
   199         if !passResult { t.Error(finalResultSummaryString) }
   200  }
   201  func kafka_3kb_pause_3kb() {
   202          time.Sleep(40 * time.Second)
   203          fmt.Println("Pausing the Kafka brokers")
   204          executeCmd("docker pause kafka0 kafka1 kafka2; sleep 30 ; docker unpause kafka0 kafka1 kafka2")
   205          fmt.Println("All the kafka brokers are restarted")
   206  }
   207  
   208  // For tests 92 and 93:
   209  // As code works now, traffic will be dropped when orderer stops, so
   210  // the number of transactions and blocks DELIVERED to consumers watching that
   211  // orderer will be lower. So the OTE testcase will fail - BUT
   212  // we could manually verify the ACK'd TXs match the delivered.
   213  
   214  //92 stop an orderer (not orderer0, so we can still see progress logs)
   215  func Test_ORD92_100000TX_1ch_3ord_kafka_3kbs(t *testing.T) {
   216          //go executeCmd("sleep 40; docker stop orderer1")
   217          go stopAndStart("orderer1")
   218          passResult, finalResultSummaryString := ote("ORD-92", 60000, 1, 3, "kafka", 3, false, 1 )
   219          if !passResult { t.Error(finalResultSummaryString) }
   220  }
   221  
   222  //93 pause an orderer (not orderer0, so we can still see progress logs)
   223  func Test_ORD93_100000TX_1ch_3ord_kafka_3kbs(t *testing.T) {
   224          //go executeCmd("sleep 40; docker pause orderer1")
   225          go pauseAndUnpause("orderer1")
   226          passResult, finalResultSummaryString := ote("ORD-93", 60000, 1, 3, "kafka", 3, false, 1 )
   227          if !passResult { t.Error(finalResultSummaryString) }
   228  }
   229