How to use launch method of launcher Package

Best Rod code snippet using launcher.launch

runtime_launcher_test.go

Source:runtime_launcher_test.go Github

copy

Full Screen

...18 var (19 fakePackageProvider *mock.PackageProvider20 fakeRuntime *mock.Runtime21 fakeRegistry *fake.LaunchRegistry22 launchState *chaincode.LaunchState23 fakeLaunchDuration *metricsfakes.Histogram24 fakeLaunchFailures *metricsfakes.Counter25 fakeLaunchTimeouts *metricsfakes.Counter26 exitedCh chan int27 ccci *ccprovider.ChaincodeContainerInfo28 runtimeLauncher *chaincode.RuntimeLauncher29 )30 BeforeEach(func() {31 launchState = chaincode.NewLaunchState()32 fakeRegistry = &fake.LaunchRegistry{}33 fakeRegistry.LaunchingReturns(launchState, false)34 fakeRuntime = &mock.Runtime{}35 fakeRuntime.StartStub = func(*ccprovider.ChaincodeContainerInfo, []byte) error {36 launchState.Notify(nil)37 return nil38 }39 exitedCh = make(chan int)40 waitExitCh := exitedCh // shadow to avoid race41 fakeRuntime.WaitStub = func(*ccprovider.ChaincodeContainerInfo) (int, error) {42 return <-waitExitCh, nil43 }44 fakePackageProvider = &mock.PackageProvider{}45 fakePackageProvider.GetChaincodeCodePackageReturns([]byte("code-package"), nil)46 fakeLaunchDuration = &metricsfakes.Histogram{}47 fakeLaunchDuration.WithReturns(fakeLaunchDuration)48 fakeLaunchFailures = &metricsfakes.Counter{}49 fakeLaunchFailures.WithReturns(fakeLaunchFailures)50 fakeLaunchTimeouts = &metricsfakes.Counter{}51 fakeLaunchTimeouts.WithReturns(fakeLaunchTimeouts)52 launchMetrics := &chaincode.LaunchMetrics{53 LaunchDuration: fakeLaunchDuration,54 LaunchFailures: fakeLaunchFailures,55 LaunchTimeouts: fakeLaunchTimeouts,56 }57 ccci = &ccprovider.ChaincodeContainerInfo{58 Name: "chaincode-name",59 Path: "chaincode-path",60 Version: "chaincode-version",61 ContainerType: "chaincode-container-type",62 Type: "chaincode-type",63 }64 runtimeLauncher = &chaincode.RuntimeLauncher{65 Runtime: fakeRuntime,66 Registry: fakeRegistry,67 PackageProvider: fakePackageProvider,68 StartupTimeout: 5 * time.Second,69 Metrics: launchMetrics,70 }71 })72 AfterEach(func() {73 close(exitedCh)74 })75 It("registers the chaincode as launching", func() {76 err := runtimeLauncher.Launch(ccci)77 Expect(err).NotTo(HaveOccurred())78 Expect(fakeRegistry.LaunchingCallCount()).To(Equal(1))79 cname := fakeRegistry.LaunchingArgsForCall(0)80 Expect(cname).To(Equal("chaincode-name:chaincode-version"))81 })82 It("starts the runtime for the chaincode", func() {83 err := runtimeLauncher.Launch(ccci)84 Expect(err).NotTo(HaveOccurred())85 Expect(fakeRuntime.StartCallCount()).To(Equal(1))86 ccciArg, codePackage := fakeRuntime.StartArgsForCall(0)87 Expect(ccciArg).To(Equal(ccci))88 Expect(codePackage).To(Equal([]byte("code-package")))89 })90 It("waits for the launch to complete", func() {91 fakeRuntime.StartReturns(nil)92 errCh := make(chan error, 1)93 go func() { errCh <- runtimeLauncher.Launch(ccci) }()94 Consistently(errCh).ShouldNot(Receive())95 launchState.Notify(nil)96 Eventually(errCh).Should(Receive(BeNil()))97 })98 It("does not deregister the chaincode", func() {99 err := runtimeLauncher.Launch(ccci)100 Expect(err).NotTo(HaveOccurred())101 Expect(fakeRegistry.DeregisterCallCount()).To(Equal(0))102 })103 It("records launch duration", func() {104 err := runtimeLauncher.Launch(ccci)105 Expect(err).NotTo(HaveOccurred())106 Expect(fakeLaunchDuration.WithCallCount()).To(Equal(1))107 labelValues := fakeLaunchDuration.WithArgsForCall(0)108 Expect(labelValues).To(Equal([]string{109 "chaincode", "chaincode-name:chaincode-version",110 "success", "true",111 }))112 Expect(fakeLaunchDuration.ObserveArgsForCall(0)).NotTo(BeZero())113 Expect(fakeLaunchDuration.ObserveArgsForCall(0)).To(BeNumerically("<", 1.0))114 })115 Context("when starting the runtime fails", func() {116 BeforeEach(func() {117 fakeRuntime.StartReturns(errors.New("banana"))118 })119 It("returns a wrapped error", func() {120 err := runtimeLauncher.Launch(ccci)121 Expect(err).To(MatchError("error starting container: banana"))122 })123 It("notifies the LaunchState", func() {124 runtimeLauncher.Launch(ccci)125 Eventually(launchState.Done()).Should(BeClosed())126 Expect(launchState.Err()).To(MatchError("error starting container: banana"))127 })128 It("records chaincode launch failures", func() {129 runtimeLauncher.Launch(ccci)130 Expect(fakeLaunchFailures.WithCallCount()).To(Equal(1))131 labelValues := fakeLaunchFailures.WithArgsForCall(0)132 Expect(labelValues).To(Equal([]string{133 "chaincode", "chaincode-name:chaincode-version",134 }))135 Expect(fakeLaunchFailures.AddCallCount()).To(Equal(1))136 Expect(fakeLaunchFailures.AddArgsForCall(0)).To(BeNumerically("~", 1.0))137 })138 It("stops the runtime", func() {139 runtimeLauncher.Launch(ccci)140 Expect(fakeRuntime.StopCallCount()).To(Equal(1))141 ccciArg := fakeRuntime.StopArgsForCall(0)142 Expect(ccciArg).To(Equal(ccci))143 })144 It("deregisters the chaincode", func() {145 runtimeLauncher.Launch(ccci)146 Expect(fakeRegistry.DeregisterCallCount()).To(Equal(1))147 cname := fakeRegistry.DeregisterArgsForCall(0)148 Expect(cname).To(Equal("chaincode-name:chaincode-version"))149 })150 })151 Context("when the contaienr terminates before registration", func() {152 BeforeEach(func() {153 fakeRuntime.StartReturns(nil)154 fakeRuntime.WaitReturns(-99, nil)155 })156 It("returns an error", func() {157 err := runtimeLauncher.Launch(ccci)158 Expect(err).To(MatchError("chaincode registration failed: container exited with -99"))159 })160 It("attempts to stop the runtime", func() {161 runtimeLauncher.Launch(ccci)162 Expect(fakeRuntime.StopCallCount()).To(Equal(1))163 ccciArg := fakeRuntime.StopArgsForCall(0)164 Expect(ccciArg).To(Equal(ccci))165 })166 It("deregisters the chaincode", func() {167 runtimeLauncher.Launch(ccci)168 Expect(fakeRegistry.DeregisterCallCount()).To(Equal(1))169 cname := fakeRegistry.DeregisterArgsForCall(0)170 Expect(cname).To(Equal("chaincode-name:chaincode-version"))171 })172 })173 Context("when handler registration fails", func() {174 BeforeEach(func() {175 fakeRuntime.StartStub = func(*ccprovider.ChaincodeContainerInfo, []byte) error {176 launchState.Notify(errors.New("papaya"))177 return nil178 }179 })180 It("returns an error", func() {181 err := runtimeLauncher.Launch(ccci)182 Expect(err).To(MatchError("chaincode registration failed: papaya"))183 })184 It("stops the runtime", func() {185 runtimeLauncher.Launch(ccci)186 Expect(fakeRuntime.StopCallCount()).To(Equal(1))187 ccciArg := fakeRuntime.StopArgsForCall(0)188 Expect(ccciArg).To(Equal(ccci))189 })190 It("deregisters the chaincode", func() {191 runtimeLauncher.Launch(ccci)192 Expect(fakeRegistry.DeregisterCallCount()).To(Equal(1))193 cname := fakeRegistry.DeregisterArgsForCall(0)194 Expect(cname).To(Equal("chaincode-name:chaincode-version"))195 })196 })197 Context("when the runtime startup times out", func() {198 BeforeEach(func() {199 fakeRuntime.StartReturns(nil)200 runtimeLauncher.StartupTimeout = 250 * time.Millisecond201 })202 It("returns a meaningful error", func() {203 err := runtimeLauncher.Launch(ccci)204 Expect(err).To(MatchError("timeout expired while starting chaincode chaincode-name:chaincode-version for transaction"))205 })206 It("notifies the LaunchState", func() {207 runtimeLauncher.Launch(ccci)208 Eventually(launchState.Done()).Should(BeClosed())209 Expect(launchState.Err()).To(MatchError("timeout expired while starting chaincode chaincode-name:chaincode-version for transaction"))210 })211 It("records chaincode launch timeouts", func() {212 runtimeLauncher.Launch(ccci)213 Expect(fakeLaunchTimeouts.WithCallCount()).To(Equal(1))214 labelValues := fakeLaunchTimeouts.WithArgsForCall(0)215 Expect(labelValues).To(Equal([]string{216 "chaincode", "chaincode-name:chaincode-version",217 }))218 Expect(fakeLaunchTimeouts.AddCallCount()).To(Equal(1))219 Expect(fakeLaunchTimeouts.AddArgsForCall(0)).To(BeNumerically("~", 1.0))220 })221 It("stops the runtime", func() {222 runtimeLauncher.Launch(ccci)223 Expect(fakeRuntime.StopCallCount()).To(Equal(1))224 ccciArg := fakeRuntime.StopArgsForCall(0)225 Expect(ccciArg).To(Equal(ccci))226 })227 It("deregisters the chaincode", func() {228 runtimeLauncher.Launch(ccci)229 Expect(fakeRegistry.DeregisterCallCount()).To(Equal(1))230 cname := fakeRegistry.DeregisterArgsForCall(0)231 Expect(cname).To(Equal("chaincode-name:chaincode-version"))232 })233 })234 Context("when the registry indicates the chaincode has already been started", func() {235 BeforeEach(func() {236 fakeRegistry.LaunchingReturns(launchState, true)237 })238 It("does not start the runtime for the chaincode", func() {239 launchState.Notify(nil)240 err := runtimeLauncher.Launch(ccci)241 Expect(err).NotTo(HaveOccurred())242 Expect(fakeRuntime.StartCallCount()).To(Equal(0))243 })244 It("waits for the launch to complete", func() {245 fakeRuntime.StartReturns(nil)246 errCh := make(chan error, 1)247 go func() { errCh <- runtimeLauncher.Launch(ccci) }()248 Consistently(errCh).ShouldNot(Receive())249 launchState.Notify(nil)250 Eventually(errCh).Should(Receive(BeNil()))251 })252 Context("when the launch fails", func() {253 BeforeEach(func() {254 launchState.Notify(errors.New("gooey-guac"))255 })256 It("does not deregister the chaincode", func() {257 err := runtimeLauncher.Launch(ccci)258 Expect(err).To(MatchError("chaincode registration failed: gooey-guac"))259 Expect(fakeRegistry.DeregisterCallCount()).To(Equal(0))260 })261 It("does not stop the runtime", func() {262 err := runtimeLauncher.Launch(ccci)263 Expect(err).To(MatchError("chaincode registration failed: gooey-guac"))264 Expect(fakeRuntime.StopCallCount()).To(Equal(0))265 })266 })267 })268 Context("when stopping the runtime fails", func() {...

Full Screen

Full Screen

launch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 launcher.Launch()4 fmt.Println("2.go")5}6import "fmt"7func Launch() {8 fmt.Println("launcher.go")9}10I was able to get it to work by renaming the launcher directory to launcherlib and then changing the import statement in 1.go to launcherlib. Thanks!11I was able to get it to work by renaming the launcher directory to launcherlib and then changing the import statement in 1.go to launcherlib. Thanks!12I was able to get it to work by renaming the launcher directory to launcherlib and then changing the import statement in 1.go to launcherlib. Thanks!

Full Screen

Full Screen

launch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello world")4 launcher.Launch()5}6import (7func Launch() {8 fmt.Println("Launching")9}10import (11func TestLaunch(t *testing.T) {12 Launch()13}14import (15func BenchmarkLaunch(b *testing.B) {16 for i := 0; i < b.N; i++ {17 Launch()18 }19}20import "fmt"21func ExampleLaunch() {22 Launch()23}

Full Screen

Full Screen

launch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("code to use launch method of launcher class")4 launcher.Launch()5}6import "fmt"7func Launch() {8 fmt.Println("Launching...")9}

Full Screen

Full Screen

launch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 launcher.Launch()4 fmt.Println("Hello World")5}6import "fmt"7func Launch() {8 fmt.Println("Launching")9}

Full Screen

Full Screen

launch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 fmt.Println(launcher.Launch())5}6import (7func Launch() string {8 return fmt.Sprintf("Launch")9}10import (11func TestLaunch(t *testing.T) {12 if Launch() != "Launch" {13 t.Fatal("Launch")14 }15}16import (17func BenchmarkLaunch(b *testing.B) {18 for i := 0; i < b.N; i++ {19 Launch()20 }21}22import (23func ExampleLaunch() {24 fmt.Println(Launch())25}26import (27func BenchmarkLaunch(b *testing.B) {28 for i := 0; i < b.N; i++ {29 Launch()30 }31}32import (33func ExampleLaunch() {34 fmt.Println(Launch())35}36import (37func BenchmarkLaunch(b *testing.B) {38 for i := 0; i < b.N; i++ {39 Launch()40 }41}42import (43func ExampleLaunch() {44 fmt.Println(Launch())45}46import (47func BenchmarkLaunch(b *testing.B) {48 for i := 0; i < b.N; i++ {49 Launch()50 }51}52import (53func ExampleLaunch() {54 fmt.Println(Launch())55}

Full Screen

Full Screen

launch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 launcher := new(Launcher)4 launcher.Launch()5}6import (7type Launcher struct {8}9func (l *Launcher) Launch() {10 fmt.Println("Launching...")11}12import (13type Launcher struct {14}15func (l *Launcher) Launch() {16 fmt.Println("Launching...")17}18import (19type Launcher struct {20}21func (l *Launcher) Launch() {22 fmt.Println("Launching...")23}24import (25type Launcher struct {26}27func (l *Launcher) Launch() {28 fmt.Println("Launching...")29}

Full Screen

Full Screen

launch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 launcher.Launch()4 fmt.Println("2.go")5}6import "fmt"7func Launch() {8 fmt.Println("launcher.go")9}10import (11func main() {12 launcher.Launch()13 fmt.Println("3.go")14}15import "fmt"16func Launch() {17 fmt.Println("launcher.go")18}19import (20func main() {21 launcher.Launch()22 fmt.Println("4.go")23}24import "fmt"25func Launch() {26 fmt.Println("launcher.go")27}28import (29func main() {30 launcher.Launch()31 fmt.Println("5.go")32}33import "fmt"34func Launch() {35 fmt.Println("launcher.go")36}37import (38func main() {39 launcher.Launch()40 fmt.Println("6.go")41}42import "fmt"43func Launch() {44 fmt.Println("launcher.go")45}46import (47func main() {48 launcher.Launch()49 fmt.Println("7.go")50}51import "fmt"52func Launch() {53 fmt.Println("launcher.go")54}55import (56func main() {57 launcher.Launch()58 fmt.Println("8.go")59}60import "fmt"61func Launch() {62 fmt.Println("launcher.go")63}64import (

Full Screen

Full Screen

launch

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Starting...")4 launcher.Launch()5 fmt.Println("Done!")6}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful