How to use NewPool method of compiler Package

Best K6 code snippet using compiler.NewPool

lua_test.go

Source:lua_test.go Github

copy

Full Screen

...16 if err != nil {17 panic(err.Error())18 }19 sdb := state.NewDatabase(db)20 pool := state.NewPool(sdb)21 main := NewMethod(vm.Public, "main", 0, 1)22 lc := Contract{23 info: vm.ContractInfo{Prefix: "test", GasLimit: 10000},24 code: `function main()25 Put("hello", "world")26 return "success"27end`,28 main: main,29 }30 lvm := VM{}31 lvm.Prepare(nil)32 lvm.Start(&lc)33 ret, _, err := lvm.call(pool, "main")34 lvm.Stop()35 So(err, ShouldBeNil)36 v, err := pool.Get("testhello")37 So(err, ShouldBeNil)38 So(ret[0].EncodeString(), ShouldEqual, "ssuccess")39 So(v.EncodeString(), ShouldEqual, "sworld")40 })41 Convey("Transfer", func() {42 db, err := db2.DatabaseFactory("redis")43 if err != nil {44 panic(err.Error())45 }46 sdb := state.NewDatabase(db)47 pool := state.NewPool(sdb)48 pool.PutHM("iost", "a", state.MakeVFloat(100000))49 pool.PutHM("iost", "b", state.MakeVFloat(100000))50 main := NewMethod(vm.Public, "main", 0, 1)51 lc := Contract{52 info: vm.ContractInfo{Prefix: "test", GasLimit: 100000, Publisher: vm.IOSTAccount("a")},53 code: `function main()54 return Transfer("a", "b", 50)55end`,56 main: main,57 }58 lvm := VM{}59 lvm.Prepare(nil)60 lvm.Start(&lc)61 rtn, _, err := lvm.call(pool, "main")62 lvm.Stop()63 So(err, ShouldBeNil)64 So(rtn[0].EncodeString(), ShouldEqual, "true")65 })66 Convey("Fatal", func() {67 db, err := db2.DatabaseFactory("redis")68 if err != nil {69 panic(err.Error())70 }71 sdb := state.NewDatabase(db)72 pool := state.NewPool(sdb)73 pool.PutHM("iost", "a", state.MakeVFloat(10))74 pool.PutHM("iost", "b", state.MakeVFloat(100))75 main := NewMethod(vm.Public, "main", 0, 0)76 lc := Contract{77 info: vm.ContractInfo{Prefix: "test", GasLimit: 10000, Publisher: vm.IOSTAccount("a")},78 code: `function main()79 Assert(Transfer("a", "b", 50))80end`,81 main: main,82 }83 lvm := VM{}84 lvm.Prepare(nil)85 lvm.Start(&lc)86 _, _, err = lvm.call(pool, "main")87 lvm.Stop()88 So(err, ShouldNotBeNil)89 })90 Convey("Fatal with no bool assert", func() {91 db, err := db2.DatabaseFactory("redis")92 if err != nil {93 panic(err.Error())94 }95 sdb := state.NewDatabase(db)96 pool := state.NewPool(sdb)97 pool.PutHM("iost", "a", state.MakeVFloat(10))98 pool.PutHM("iost", "b", state.MakeVFloat(100))99 main := NewMethod(vm.Public, "main", 0, 0)100 lc := Contract{101 info: vm.ContractInfo{Prefix: "test", GasLimit: 10000, Publisher: vm.IOSTAccount("a")},102 code: `function main()103 Assert("hello")104end`,105 main: main,106 }107 lvm := VM{}108 lvm.Prepare(nil)109 lvm.Start(&lc)110 _, _, err = lvm.call(pool, "main")111 lvm.Stop()112 So(err, ShouldNotBeNil)113 })114 Convey("Out of gas", func() {115 db, err := db2.DatabaseFactory("redis")116 if err != nil {117 panic(err.Error())118 }119 sdb := state.NewDatabase(db)120 pool := state.NewPool(sdb)121 main := NewMethod(vm.Public, "main", 0, 1)122 lc := Contract{123 info: vm.ContractInfo{Prefix: "test", GasLimit: 3},124 code: `function main()125 Put("hello", "world")126 return "success"127end`,128 main: main,129 }130 lvm := VM{}131 lvm.Prepare(nil)132 lvm.Start(&lc)133 _, _, err = lvm.call(pool, "main")134 lvm.Stop()135 So(err, ShouldNotBeNil)136 })137 })138 Convey("Test of Lua value converter", t, func() {139 Convey("Lua to core", func() {140 Convey("string", func() {141 lstr := lua.LString("hello")142 cstr, _ := Lua2Core(lstr)143 So(cstr.Type(), ShouldEqual, state.String)144 So(cstr.EncodeString(), ShouldEqual, "shello")145 lbool := lua.LTrue146 cbool, _ := Lua2Core(lbool)147 So(cbool.Type(), ShouldEqual, state.Bool)148 So(cbool.EncodeString(), ShouldEqual, "true")149 lnum := lua.LNumber(3.14)150 cnum, _ := Lua2Core(lnum)151 So(cnum.Type(), ShouldEqual, state.Float)152 So(cnum.EncodeString(), ShouldEqual, "f3.140000000000000e+00")153 })154 })155 })156}157func TestTransfer(t *testing.T) {158 Convey("Test lua transfer", t, func() {159 main := NewMethod(vm.Public, "main", 0, 1)160 lc := Contract{161 info: vm.ContractInfo{Prefix: "test", GasLimit: 1000, Publisher: vm.IOSTAccount("a")},162 code: `function main()163 Transfer("a", "b", 50)164 return "success"165end`,166 main: main,167 }168 lvm := VM{}169 db, err := db2.DatabaseFactory("redis")170 if err != nil {171 panic(err.Error())172 }173 sdb := state.NewDatabase(db)174 pool := state.NewPool(sdb)175 pool.PutHM("iost", "a", state.MakeVFloat(5000))176 pool.PutHM("iost", "b", state.MakeVFloat(1000))177 lvm.Prepare(nil)178 lvm.Start(&lc)179 _, pool, err = lvm.call(pool, "main")180 lvm.Stop()181 ab, err := pool.GetHM("iost", "a")182 bb, err := pool.GetHM("iost", "b")183 So(err, ShouldBeNil)184 So(ab.(*state.VFloat).ToFloat64(), ShouldEqual, 4950)185 So(bb.(*state.VFloat).ToFloat64(), ShouldEqual, 1050)186 })187}188func BenchmarkLuaVM_SetupAndCalc(b *testing.B) {189 main := NewMethod(vm.Public, "main", 0, 1)190 lc := Contract{191 info: vm.ContractInfo{Prefix: "test", GasLimit: 11},192 code: `function main()193 return "success"194end`,195 main: main,196 }197 lvm := VM{}198 db, err := db2.DatabaseFactory("redis")199 if err != nil {200 panic(err.Error())201 }202 sdb := state.NewDatabase(db)203 pool := state.NewPool(sdb)204 for i := 0; i < b.N; i++ {205 lvm.Prepare(nil)206 lvm.Start(&lc)207 lvm.call(pool, "main")208 lvm.Stop()209 }210}211func BenchmarkLuaVM_10000LuaGas(b *testing.B) {212 main := NewMethod(vm.Public, "main", 0, 1)213 lc := Contract{214 info: vm.ContractInfo{Prefix: "test", GasLimit: 10000},215 code: `function main()216 while( true )217do218 i = 1219end220 return "success"221end`,222 main: main,223 }224 lvm := VM{}225 db, err := db2.DatabaseFactory("redis")226 if err != nil {227 panic(err.Error())228 }229 sdb := state.NewDatabase(db)230 pool := state.NewPool(sdb)231 for i := 0; i < b.N; i++ {232 lvm.Prepare(nil)233 lvm.Start(&lc)234 lvm.call(pool, "main")235 lvm.Stop()236 }237}238func BenchmarkLuaVM_GetInPatch(b *testing.B) {239 main := NewMethod(vm.Public, "main", 0, 1)240 lc := Contract{241 info: vm.ContractInfo{Prefix: "test", GasLimit: 1000},242 code: `function main()243 Get("hello")244 return "success"245end`,246 main: main,247 }248 lvm := VM{}249 db, err := db2.DatabaseFactory("redis")250 if err != nil {251 panic(err.Error())252 }253 sdb := state.NewDatabase(db)254 pool := state.NewPool(sdb)255 pool.Put("hello", state.MakeVString("world"))256 for i := 0; i < b.N; i++ {257 lvm.Prepare(nil)258 lvm.Start(&lc)259 lvm.call(pool, "main")260 lvm.Stop()261 }262}263func BenchmarkLuaVM_PutToPatch(b *testing.B) {264 main := NewMethod(vm.Public, "main", 0, 1)265 lc := Contract{266 info: vm.ContractInfo{Prefix: "test", GasLimit: 1000},267 code: `function main()268 Put("hello", "world")269 return "success"270end`,271 main: main,272 }273 lvm := VM{}274 db, err := db2.DatabaseFactory("redis")275 if err != nil {276 panic(err.Error())277 }278 sdb := state.NewDatabase(db)279 pool := state.NewPool(sdb)280 for i := 0; i < b.N; i++ {281 lvm.Prepare(nil)282 lvm.Start(&lc)283 lvm.call(pool, "main")284 lvm.Stop()285 }286}287func BenchmarkLuaVM_Transfer(b *testing.B) {288 main := NewMethod(vm.Public, "main", 0, 1)289 lc := Contract{290 info: vm.ContractInfo{Prefix: "test", GasLimit: 1000, Publisher: vm.IOSTAccount("a")},291 code: `function main()292 Transfer("a", "b", 50)293 return "success"294end`,295 main: main,296 }297 lvm := VM{}298 db, err := db2.DatabaseFactory("redis")299 if err != nil {300 panic(err.Error())301 }302 sdb := state.NewDatabase(db)303 pool := state.NewPool(sdb)304 pool.PutHM("iost", "a", state.MakeVFloat(5000))305 pool.PutHM("iost", "b", state.MakeVFloat(50))306 for i := 0; i < b.N; i++ {307 lvm.Prepare(nil)308 lvm.Start(&lc)309 _, _, err = lvm.call(pool, "main")310 lvm.Stop()311 }312}313func TestCompilerNaive(t *testing.T) {314 Convey("test of parse", t, func() {315 parser, _ := NewDocCommentParser(316 `317--- main 合约主入口318-- server1转账server2319-- @gas_limit 11320-- @gas_price 0.0001321-- @param_cnt 0322-- @return_cnt 1323function main()324 print("hello")325 Transfer("abc","mSS7EdV7WvBAiv7TChww7WE3fKDkEYRcVguznbQspj4K", 10)326end--f327`)328 contract, err := parser.Parse()329 So(err, ShouldBeNil)330 So(contract.info.Language, ShouldEqual, "lua")331 So(contract.info.GasLimit, ShouldEqual, 11)332 So(contract.info.Price, ShouldEqual, 0.0001)333 fmt.Println(contract.code)334 So(contract.main, ShouldResemble, Method{"main", 0, 1, vm.Private})335 })336}337func TestContract(t *testing.T) {338 main := NewMethod(vm.Public, "main", 0, 1)339 Convey("Test of lua contract", t, func() {340 lc := Contract{341 info: vm.ContractInfo{GasLimit: 1000, Price: 0.1},342 code: `function main()343 Transfer("a", "b", 50)344 return "success"345end`,346 main: main,347 }348 buf := lc.Encode()349 var lc2 Contract350 err := lc2.Decode(buf)351 So(err, ShouldBeNil)352 So(lc2.info.GasLimit, ShouldEqual, lc.info.GasLimit)353 So(lc2.Code(), ShouldEqual, lc.code)354 })355}356func TestContract2(t *testing.T) {357 errlua := `--- main 一元夺宝358-- snatch treasure with 1 coin !359-- @gas_limit 100000360-- @gas_price 0.01361-- @param_cnt 0362-- @return_cnt 1363-- @publisher walleta364function main()365 Put("max_user_number", 20)366 Put("user_number", 0)367 Put("winner", "")368 Put("claimed", "false")369 return "success"370end--f371--- BuyCoin buy coins372-- buy some coins373-- @param_cnt 2374-- @return_cnt 1375function BuyCoin(account, buyNumber)376 if (buyNumber <= 0)377 then378 return "buy number should be more than zero"379 end380 maxUserNumber = Get("max_user_number")381 number = Get("user_number")382 if (number >= maxUserNumber or number + buyNumber > maxUserNumber)383 then384 return string.format("max user number exceed, only %d coins left", maxUserNumber - number)385 end386 -- print(string.format("deposit account = %s, number = %d", account, buyNumber))387 Deposit(account, buyNumber)388 win = false389 for i = 0, buyNumber - 1, 1 do390 win = win or winAfterBuyOne(number)391 number = number + 1392 end393 Put("user_number", number)394 if (win)395 then396 Put("winner", account)397 end398 return "success"399end--f400--- winAfterBuyOne win after buy one401-- @param_cnt 1402-- @return_cnt 1403function winAfterBuyOne(number)404 win = Random(1 - 1.0 / (number + 1))405 return win406end--f407--- QueryWinner query winner408-- @param_cnt 0409-- @return_cnt 1410function QueryWinner()411 return Get("winner")412end--f413--- QueryClaimed query claimed414-- @param_cnt 0415-- @return_cnt 1416function QueryClaimed()417 return Get("claimed")418end--f419--- QueryUserNumber query user number 420-- @param_cnt 0421-- @return_cnt 1422function QueryUserNumber()423 return Get("user_number")424end--f425--- QueryMaxUserNumber query max user number 426-- @param_cnt 0427-- @return_cnt 1428function QueryMaxUserNumber()429 return Get("max_user_number")430end--f431--- Claim claim prize432-- @param_cnt 0433-- @return_cnt 1434function Claim()435 claimed = Get("claimed")436 if (claimed == "true")437 then438 return "price has been claimed"439 end440 number = Get("user_number")441 maxUserNumber = Get("max_user_number")442 if (number < maxUserNumber)443 then444 return string.format("game not end yet! user_number = %d, max_user_number = %d", number, maxUserNumber)445 end446 winner = Get("winner")447 Put("claimed", "true")448 Withdraw(winner, number)449 return "success"450end--f451`452 Convey("test of encode", t, func() {453 parser, err := NewDocCommentParser(errlua)454 So(err, ShouldBeNil)455 sc, err := parser.Parse()456 So(err, ShouldBeNil)457 buf := sc.Encode()458 var sc2 Contract459 sc2.Decode(buf)460 fmt.Println()461 So(bytes.Equal(sc.Encode(), sc2.Encode()), ShouldBeTrue)462 })463}464func TestContext(t *testing.T) {465 Convey("Test context privilege", t, func() {466 main := NewMethod(vm.Public, "main", 0, 1)467 lc := Contract{468 info: vm.ContractInfo{Prefix: "test", GasLimit: 10000, Publisher: vm.IOSTAccount("b")},469 code: `function main()470 Transfer("a", "b", 50)471 return "success"472end`,473 main: main,474 }475 lvm := VM{}476 db, err := db2.DatabaseFactory("redis")477 if err != nil {478 panic(err.Error())479 }480 sdb := state.NewDatabase(db)481 pool := state.NewPool(sdb)482 pool.PutHM("iost", "a", state.MakeVFloat(5000))483 pool.PutHM("iost", "b", state.MakeVFloat(1000))484 lvm.Prepare(nil)485 lvm.Start(&lc)486 ctx := &vm.Context{487 Publisher: vm.IOSTAccount("a"),488 }489 _, pool, err = lvm.Call(ctx, pool, "main")490 lvm.Stop()491 ab, err := pool.GetHM("iost", "a")492 bb, err := pool.GetHM("iost", "b")493 So(err, ShouldBeNil)494 So(ab.(*state.VFloat).ToFloat64(), ShouldEqual, 4950)495 So(bb.(*state.VFloat).ToFloat64(), ShouldEqual, 1050)496 })497}498func TestVM_Restart(t *testing.T) {499 Convey("test of restart a vm", t, func() {500 db, err := db2.DatabaseFactory("redis")501 if err != nil {502 panic(err.Error())503 }504 sdb := state.NewDatabase(db)505 pool := state.NewPool(sdb)506 pool.PutHM("iost", "a", state.MakeVFloat(5000))507 pool.PutHM("iost", "b", state.MakeVFloat(1000))508 main := NewMethod(vm.Public, "main", 0, 1)509 lc := Contract{510 info: vm.ContractInfo{Prefix: "test", GasLimit: 1000, Publisher: vm.IOSTAccount("a")},511 code: `function main()512 Transfer("a", "b", 50)513 return "success"514end`,515 main: main,516 }517 lc2 := Contract{518 info: vm.ContractInfo{Prefix: "test", GasLimit: 10000, Publisher: vm.IOSTAccount("a")},519 code: `function main()520 Transfer("a", "b", 100)521 return "success"522end`,523 main: main,524 }525 var lvm VM526 lvm.Prepare(nil)527 err = lvm.Start(&lc)528 So(err, ShouldBeNil)529 So(lvm.PC(), ShouldEqual, 3)530 lvm.Call(vm.BaseContext(), pool, "main")531 So(lvm.PC(), ShouldEqual, 7)532 So(lvm.L.PCLimit, ShouldEqual, 1000)533 lvm.Restart(&lc2)534 So(lvm.L.PCLimit, ShouldEqual, 10000)535 })536}537func TestTable(t *testing.T) {538 Convey("test of table", t, func() {539 db, err := db2.DatabaseFactory("redis")540 if err != nil {541 panic(err.Error())542 }543 sdb := state.NewDatabase(db)544 pool := state.NewPool(sdb)545 main := NewMethod(vm.Public, "main", 0, 1)546 lc := Contract{547 info: vm.ContractInfo{GasLimit: 1000, Price: 0.1},548 code: `function main()549 test = {}550 test["a"] = 1551 test["b"] = 2552 Put("test", test)553 return "success"554end`,555 main: main,556 }557 lvm := VM{}558 lvm.Prepare(nil)559 lvm.Start(&lc)560 _, pool, err = lvm.call(pool, "main")561 lvm.Stop()562 So(err, ShouldNotBeNil)563 pool.Flush()564 fmt.Println(pool.GetHM("test", "a"))565 })566 Convey("test of table encode", t, func() {567 db, err := db2.DatabaseFactory("redis")568 if err != nil {569 panic(err.Error())570 }571 sdb := state.NewDatabase(db)572 pool := state.NewPool(sdb)573 main := NewMethod(vm.Public, "main", 0, 1)574 lc := Contract{575 info: vm.ContractInfo{GasLimit: 1000, Price: 0.1},576 code: `function main()577 test = {}578 test["a"] = 1579 test["b"] = 2580 test2 = {}581 test2[1] = "ahaha"582 test2[2] = "ohoho"583 test["t"] = test2584 ok, str = ToJson(test)585 print(str)586 ok, tab = ParseJson(str)587 for key, value in pairs(tab) do 588 print(key, value)589 end 590 591 return "success"592end`,593 main: main,594 }595 lvm := VM{}596 lvm.Prepare(nil)597 lvm.Start(&lc)598 _, pool, err = lvm.call(pool, "main")599 lvm.Stop()600 })601}602func TestLog(t *testing.T) {603 Convey("test of table", t, func() {604 db, err := db2.DatabaseFactory("redis")605 if err != nil {606 panic(err.Error())607 }608 sdb := state.NewDatabase(db)609 pool := state.NewPool(sdb)610 main := NewMethod(vm.Public, "main", 0, 1)611 lc := Contract{612 info: vm.ContractInfo{GasLimit: 1000, Price: 0.1},613 code: `function main()614 Log("hello world")615end`,616 main: main,617 }618 lvm := VM{}619 lvm.Prepare(nil)620 lvm.Start(&lc)621 _, pool, err = lvm.call(pool, "main")622 lvm.Stop()623 So(err, ShouldBeNil)...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

1package main2import (3 "flag"4 "fmt"5 "log"6 "os"7 "os/signal"8 "strconv"9 "strings"10 "sync"11 "time"12 "github.com/D4-project/analyzer-d4-log/inputreader"13 "github.com/D4-project/analyzer-d4-log/logcompiler"14 config "github.com/D4-project/d4-golang-utils/config"15 "github.com/gomodule/redigo/redis"16)17type (18 // Input is a grok - NIFI or Logstash19 redisconfInput struct {20 redisHost string21 redisPort string22 redisDB int23 }24 redisconfCompilers struct {25 redisHost string26 redisPort string27 redisDBCount int28 }29 conf struct {30 httpHost string31 httpPort string32 }33)34// Setting up flags35var (36 tmpretry, _ = time.ParseDuration("30s")37 // Flags38 confdir = flag.String("c", "conf.sample", "configuration directory")39 all = flag.Bool("a", true, "run all compilers when set. Set by default")40 specific = flag.String("o", "", "run only a specific parser [sshd]")41 debug = flag.Bool("d", false, "debug info in logs")42 fromfile = flag.String("f", "", "parse from file on disk")43 retry = flag.Duration("r", tmpretry, "Time in human format before retrying to read an empty d4 queue")44 flush = flag.Bool("F", false, "Flush HTML output, recompile all statistic from redis logs, then quits")45 // Pools of redis connections46 redisCompilers *redis.Pool47 redisInput *redis.Pool48 // Compilers49 compilers = [1]string{"sshd"}50 compilationTrigger = 200051 torun = []logcompiler.Compiler{}52 // Routine handling53 pullgr sync.WaitGroup54 compilegr sync.WaitGroup55)56func main() {57 // Create a chan to get the goroutines errors messages58 pullreturn := make(chan error, 1)59 // Create a chan to get os Signals60 sortie := make(chan os.Signal, 1)61 signal.Notify(sortie, os.Interrupt, os.Kill)62 // OS signaling and error handling goroutine63 go func() {64 select {65 case <-sortie:66 fmt.Println("Exiting.")67 compilegr.Wait()68 log.Println("Exit")69 os.Exit(0)70 case err := <-pullreturn:71 log.Println(err)72 fmt.Println("Exiting.")73 compilegr.Wait()74 log.Println("Exit.")75 os.Exit(1)76 }77 }()78 // Setting up log file79 f, err := os.OpenFile("analyzer-d4-log.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)80 if err != nil {81 log.Fatalf("error opening file: %v", err)82 }83 defer f.Close()84 log.SetOutput(f)85 log.Println("Init")86 // Usage and flags87 flag.Usage = func() {88 fmt.Printf("analyzer-d4-log:\n\n")89 fmt.Printf(" Generate statistics about logs collected through d4 in HTML format.\n")90 fmt.Printf(" Logs should be groked and served as escaped JSON.\n")91 fmt.Printf("\n")92 flag.PrintDefaults()93 fmt.Printf("\n")94 fmt.Printf("The configuration directory should hold the following files\n")95 fmt.Printf("to specify the settings to use:\n\n")96 fmt.Printf(" mandatory: redis_d4 - host:port/db\n")97 fmt.Printf(" mandatory: redis_compilers - host:port/maxdb\n")98 // fmt.Printf(" optional: http_server - host:port\n\n")99 fmt.Printf("See conf.sample for an example.\n")100 }101 // Config102 // c := conf{}103 ri := redisconfInput{}104 rp := redisconfCompilers{}105 flag.Parse()106 if flag.NFlag() == 0 || *confdir == "" {107 flag.Usage()108 os.Exit(1)109 } else {110 *confdir = strings.TrimSuffix(*confdir, "/")111 *confdir = strings.TrimSuffix(*confdir, "\\")112 }113 // Debug log114 if *debug {115 log.SetFlags(log.LstdFlags | log.Lshortfile)116 }117 // Dont't touch input server if Flushing118 if !*flush {119 // Parse Input Redis Config120 tmp := config.ReadConfigFile(*confdir, "redis_input")121 ss := strings.Split(string(tmp), "/")122 if len(ss) <= 1 {123 log.Fatal("Missing Database in Redis input config: should be host:port/database_name")124 }125 ri.redisDB, _ = strconv.Atoi(ss[1])126 var ret bool127 ret, ss[0] = config.IsNet(ss[0])128 if ret {129 sss := strings.Split(string(ss[0]), ":")130 ri.redisHost = sss[0]131 ri.redisPort = sss[1]132 } else {133 log.Fatal("Redis config error.")134 }135 }136 // Parse Redis Compilers Config137 tmp := config.ReadConfigFile(*confdir, "redis_compilers")138 ss := strings.Split(string(tmp), "/")139 if len(ss) <= 1 {140 log.Fatal("Missing Database Count in Redis config: should be host:port/max number of DB")141 }142 rp.redisDBCount, _ = strconv.Atoi(ss[1])143 var ret bool144 ret, ss[0] = config.IsNet(ss[0])145 if ret {146 sss := strings.Split(string(ss[0]), ":")147 rp.redisHost = sss[0]148 rp.redisPort = sss[1]149 } else {150 log.Fatal("Redis config error.")151 }152 // Create a connection Pool for output Redis153 redisCompilers = newPool(rp.redisHost+":"+rp.redisPort, rp.redisDBCount)154 redisInput = newPool(ri.redisHost+":"+ri.redisPort, 16)155 // Init compiler depending on the compiler flags:156 if *all {157 // Init all compilers158 for _, v := range compilers {159 switch v {160 case "sshd":161 sshdrcon0, err := redisCompilers.Dial()162 if err != nil {163 log.Fatal("Could not connect to input line on Compiler Redis")164 }165 defer sshdrcon0.Close()166 sshdrcon1, err := redisCompilers.Dial()167 if err != nil {168 log.Fatal("Could not connect to output line on Compiler Redis")169 }170 defer sshdrcon1.Close()171 sshdrcon2, err := redisInput.Dial()172 if err != nil {173 log.Fatal("Could not connect to output line on Input Redis")174 }175 defer sshdrcon2.Close()176 redisReader := inputreader.NewLPOPReader(&sshdrcon2, ri.redisDB, "sshd")177 sshd := logcompiler.SSHDCompiler{}178 sshd.Set(&pullgr, &sshdrcon0, &sshdrcon1, redisReader, compilationTrigger, &compilegr, &pullreturn, *retry)179 torun = append(torun, &sshd)180 }181 }182 } else if *specific != "" {183 log.Println("TODO should run specific compiler here")184 }185 // If we flush, we bypass the compiling loop186 if *flush {187 for _, v := range torun {188 err := v.Flush()189 if err != nil {190 log.Fatal(err)191 }192 log.Println("Exit")193 os.Exit(0)194 }195 }196 // Launching Pull routines197 for _, v := range torun {198 // If we read from a file, we set the reader to os.open199 if *fromfile != "" {200 f, err = os.Open(*fromfile)201 if err != nil {202 log.Fatalf("Error opening seed file: %v", err)203 }204 defer f.Close()205 v.SetReader(f)206 }207 // we add pulling routines to a waitgroup,208 // we wait for completion on exit209 pullgr.Add(1)210 go v.Pull(pullreturn)211 }212 // Launching MISP export routines213 // they can immediately die when exiting.214 for _, v := range torun {215 go func() {216 ticker := time.NewTicker(24 * time.Hour)217 for _ = range ticker.C {218 v.MISPexport()219 }220 }()221 }222 pullgr.Wait()223 log.Println("Exit")224}225func newPool(addr string, maxconn int) *redis.Pool {226 return &redis.Pool{227 MaxActive: maxconn,228 MaxIdle: 3,229 IdleTimeout: 240 * time.Second,230 // Dial or DialContext must be set. When both are set, DialContext takes precedence over Dial.231 Dial: func() (redis.Conn, error) { return redis.Dial("tcp", addr) },232 }233}...

Full Screen

Full Screen

stringpool_test.go

Source:stringpool_test.go Github

copy

Full Screen

...31 Release(sb *strings.Builder)32}33var (34 sb *strings.Builder = &strings.Builder{}35 NewPool = New()36 out string = "" // global string return value37 global_n int = 038 global_err error = nil39 k byte40)41type swimmer struct{ strings.Builder }42func (t swimmer) Get() *strings.Builder {43 return new(strings.Builder)44}45func (t swimmer) Release(sb *strings.Builder) {46 t.Reset()47}48func sbNonPool() pooler {49 return &swimmer{}...

Full Screen

Full Screen

NewPool

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 f, err := parser.ParseFile(fset, "1.go", nil, parser.ParseComments)4 if err != nil {5 log.Fatal(err)6 }7 ast.Print(fset, f)8}

Full Screen

Full Screen

NewPool

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 prog, err := loader.Load(build.Default, []string{"golang.org/x/tools/go/ssa/ssautil"})4 if err != nil {5 fmt.Println(err)6 }7 ssaprog := ssautil.CreateProgram(prog, 0)8 ssaprog.Build()9 comp := ssautil.NewCompiler(ssaprog, 0)10 comp.Build()11 pool := ssautil.NewPool()12 pool.NewPool(comp)13}14import (15func main() {16 prog, err := loader.Load(build.Default, []string{"golang.org/x/tools/go/ssa/ssautil"})17 if err != nil {18 fmt.Println(err)19 }20 ssaprog := ssautil.CreateProgram(prog, 0)21 ssaprog.Build()22 comp := ssautil.NewCompiler(ssaprog, 0)23 comp.Build()24 pool := ssautil.NewPool()25 pool.NewPool(comp)26}27import (

Full Screen

Full Screen

NewPool

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 m := minify.New()4 m.AddFunc("text/css", css.Minify)5 m.AddFunc("text/html", html.Minify)6 m.AddFunc("image/svg+xml", svg.Minify)7 m.AddFuncRegexp(regexp.MustCompile("[/+]json$"), json.Minify)8 m.AddFuncRegexp(regexp.MustCompile("[/+]xml$"), xml.Minify)9 m.Add("text/javascript", &js.JsMinifier{10 })11 m.AddFunc("application/ld+json", jsonld.Minify)12 m.Add("application/javascript", &js.JsMinifier{13 })14 m.Add("application/ecmascript", &js.JsMinifier{15 })16 m.Add("text/ecmascript", &js.JsMinifier{17 })18 m.Add("text/javascript1.0", &js.JsMinifier{19 })20 m.Add("text/javascript1.1", &js.JsMinifier{21 })22 m.Add("text/javascript1.2", &js.JsMinifier{

Full Screen

Full Screen

NewPool

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 runtime.GOMAXPROCS(runtime.NumCPU())4 waitGroup.Add(1000)5 pool := compiler.NewPool(5)6 for i := 0; i < 1000; i++ {7 go func() {8 worker := pool.GetWorker()9 fmt.Println(worker)10 pool.ReleaseWorker(worker)11 waitGroup.Done()12 }()13 }14 waitGroup.Wait()15 pool.Shutdown()16}17import (18func main() {19 runtime.GOMAXPROCS(runtime.NumCPU())20 waitGroup.Add(1000)21 pool := compiler.NewPool(5)22 for i := 0; i < 1000; i++ {23 go func() {24 worker := pool.GetWorker()25 fmt.Println(worker)26 pool.ReleaseWorker(worker)27 waitGroup.Done()28 }()29 }30 waitGroup.Wait()31 pool.Shutdown()32}33import (

Full Screen

Full Screen

NewPool

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 pool := runtime.NewPool(2)4 pool.Submit(func() {5 fmt.Println("Hello World")6 })7 pool.Shutdown()8}9Recommended Posts: Golang | runtime.GC() method10Golang | runtime.GOMAXPROCS() method11Golang | runtime.NumCPU() method12Golang | runtime.NumGoroutine() method13Golang | runtime.NumCgoCall() method14Golang | runtime.ReadMemStats() method15Golang | runtime.SetFinalizer() method16Golang | runtime.GOMAXPROCS() method17Golang | runtime.ReadMemStats() method18Golang | runtime.NumCgoCall() method19Golang | runtime.NumGoroutine() method20Golang | runtime.GC() method21Golang | runtime.GOMAXPROCS() method22Golang | runtime.NumCPU() method23Golang | runtime.NumGoroutine() method24Golang | runtime.NumCgoCall() method25Golang | runtime.ReadMemStats() method26Golang | runtime.SetFinalizer() method27Golang | runtime.GOMAXPROCS() method28Golang | runtime.ReadMemStats() method29Golang | runtime.NumCgoCall() method30Golang | runtime.NumGoroutine() method31Golang | runtime.GC() method32Golang | runtime.GOMAXPROCS() method33Golang | runtime.NumCPU() method34Golang | runtime.NumGoroutine() method35Golang | runtime.NumCgoCall() method36Golang | runtime.ReadMemStats() method37Golang | runtime.SetFinalizer() method38Golang | runtime.GOMAXPROCS() method39Golang | runtime.ReadMemStats() method40Golang | runtime.NumCgoCall() method41Golang | runtime.NumGoroutine() method42Golang | runtime.GC() method43Golang | runtime.GOMAXPROCS() method44Golang | runtime.NumCPU() method45Golang | runtime.NumGoroutine() method46Golang | runtime.NumCgoCall() method47Golang | runtime.ReadMemStats() method

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