| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692 |
- package basic
- import (
- "encoding/json"
- "fmt"
- "testing"
- "time"
- . "git.wecise.com/wecise/odbserver/odb"
- "git.wecise.com/wecise/odbserver/odb/test"
- "gitee.com/wecisecode/util/logger"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
- )
- type BasicTests struct {
- Test *testing.T
- g *Gutil
- }
- func BasicTest(t *testing.T) {
- g := test.TestG()
- t.Run("InitG", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.InitG()
- })
- t.Run("Class", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.Class()
- })
- t.Run("Data", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.Data()
- })
- time.Sleep(time.Duration(5) * time.Second)
- t.Run("Valid", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.Valid()
- })
- t.Run("Int", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.Int()
- })
- t.Run("Bool", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.Bool()
- })
- t.Run("FullSearch", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.FullSearch()
- })
- t.Run("Prefix", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.Prefix()
- })
- t.Run("NotIn", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.NotIn()
- })
- /*t.Run("Rename", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.Rename()
- })*/
- t.Run("Float", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.Float()
- })
- t.Run("Double", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.Double()
- })
- t.Run("Aggr", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.Aggr()
- })
- t.Run("PrivateField", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.PrivateField()
- })
- t.Run("Data2", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.Data2()
- })
- t.Run("Valid2", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.Valid2()
- })
- t.Run("Int2", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.Int2()
- })
- t.Run("Bool2", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.Bool2()
- })
- t.Run("FullSearch2", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.FullSearch2()
- })
- t.Run("Prefix2", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.Prefix2()
- })
- t.Run("NotIn2", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.NotIn2()
- })
- t.Run("Float2", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.Float2()
- })
- t.Run("Double2", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.Double2()
- })
- t.Run("Aggr2", func(t *testing.T) {
- test := &BasicTests{Test: t, g: g}
- test.Aggr2()
- })
- }
- func (t *BasicTests) InitG() {
- require.NotNil(t.Test, t.g)
- // namespace test
- _, _, err := t.g.Query(` create class if not exists /test() with namespace="test" `)
- if err != nil {
- fmt.Printf("%s, %v", t.g.Keyspace, err)
- logger.Errorf("%v", err)
- }
- _, _, err = t.g.Query(` create edge type if not exists test.connect `)
- if err != nil {
- fmt.Printf("%s, %v", t.g.Keyspace, err)
- logger.Errorf("%v", err)
- }
- //normal test
- //t.g.Query(` create class if not exists /test() `)
- }
- func (t *BasicTests) Class() {
- // clear exists data
- t.g.Query(`
- delete from /test/basic with version;
- `)
- t.g.Query(`
- delete from /test/basic2 with version;
- `)
- _, _, err := t.g.Query(`
- drop class if exists /test/basic/;
- `)
- if err != nil {
- fmt.Printf("%s, %v", t.g.Keyspace, err)
- logger.Errorf("%v", err)
- }
- _, _, err = t.g.Query(`
- drop class if exists /test/basic2/;
- `)
- if err != nil {
- fmt.Printf("%s, %v", t.g.Keyspace, err)
- logger.Errorf("%v", err)
- }
- require.Nil(t.Test, err, fmt.Sprint(err))
- _, _, err = t.g.Query(`
-
- typedef if not exists STRSTR = varchar ;
- typedef if not exists DOUDOU = double ;
- `)
- if err != nil {
- fmt.Printf("%s, %v", t.g.Keyspace, err)
- logger.Errorf("%v", err)
- }
- require.Nil(t.Test, err, fmt.Sprint(err))
- _, _, err = t.g.Query(`
-
- create class if not exists /test/basic (
-
- v_varchar STRSTR,
- v_text text,
- v_int int,
- v_bigint bigint,
- v_smalldouble double,
- v_double DOUDOU,
- v_float float,
- v_bool bool,
- v_blob blob,
-
- indexes(v_varchar, v_text, v_int, v_bigint, v_double, v_float, v_smalldouble, v_bool),
- keys(v_varchar, v_text)
- );
-
- create class if not exists /test/basic2 (
-
- v_varchar STRSTR,
- v_text text,
- v_int int,
- v_bigint bigint,
- v_smalldouble double,
- v_double DOUDOU,
- v_float float,
- v_bool bool,
- v_blob blob,
-
- indexes(v_varchar, v_text, v_int, v_bigint, v_double, v_float, v_smalldouble, v_bool),
- keys(v_varchar, v_text)
- ) with core=memory ;
-
- create class if not exists /test/basic/mxfield () with autosearch=true , version=false , key=manu, nickname = 'mxfield' ;
-
- --must have nickname for private field
- alter class /test/basic with nickname='basic' ;
-
- --taget define in tools, its string
- alter class /test/basic add column target int ;
-
- --test hello:version, hello:policy field
- create class if not exists /matrix/system/test (
- version int,
- policy int,
- keys(name)
- )with nickname='hello';
- create class if not exists /test/basic2 (
- name text,
- keys(name)
- ) with nickname='basic2';
-
-
- `)
- if err != nil {
- fmt.Printf("%s, %v", t.g.Keyspace, err)
- logger.Errorf("%v", err)
- }
- require.Nil(t.Test, err, fmt.Sprint(err))
- }
- func (t *BasicTests) Data() {
- var err error
- _, _, err = t.g.Query(`insert into /matrix/system/test (name, version, policy) values ('hello', 1, 1)`)
- require.Nil(t.Test, err, fmt.Sprint(err))
- _, _, err = t.g.Query(`insert into /matrix/system/test (name, version, policy) values ('hello', 2, 2)`)
- require.Nil(t.Test, err, fmt.Sprint(err))
- _, _, err = t.g.Query(`insert into /matrix/system/test (name, version, policy) values ('hello', 3, 3)`)
- require.Nil(t.Test, err, fmt.Sprint(err))
- _, _, err = t.g.Query(`update /matrix/system/test set version = 4, policy = 4 where name = 'hello' `)
- require.Nil(t.Test, err, fmt.Sprint(err))
- _, _, err = t.g.Query(`update /matrix/system/test set version = 5, policy = 5 where name = 'hello' `)
- require.Nil(t.Test, err, fmt.Sprint(err))
- _, _, err = t.g.Query(`insert into /test/basic (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool, v_blob) values ('*abc*', 'hello word 2003 123-456-789 中华人民共和国是中国的唯一合法政府,台湾是中国一部分。 Mercury, Venus2,Earch%。Mars$Uranus CeresAndJupiterOrSaturn #Neptune Pluto_Charon"\""', 5, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456, true, "hello" )`)
- require.Nil(t.Test, err, fmt.Sprint(err))
- //reinsert
- _, _, err = t.g.Query(`insert into /test/basic (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('*abc*', 'hello word 2003 123-456-789 中华人民共和国是中国的唯一合法政府,台湾是中国一部分。 Mercury, Venus2,Earch%。Mars$Uranus CeresAndJupiterOrSaturn #Neptune Pluto_Charon"\""', 1, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456, true )`)
- require.Nil(t.Test, err, fmt.Sprint(err))
- _, _, err = t.g.Query(`insert into /test/basic (name) values ('hello')`)
- //require.Nil(t.Test, err, fmt.Sprint(err))
- _, _, err = t.g.Query(`insert into /test/basic (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('2', 'because in both case, Cassandra guarantees that these queries performance will be proportional to the amount of data returned. In particular, if no users are born in 1981, then the second query performance will not depend of the number of user profile stored in the database (not directly at least: due to secondary index implementation consideration, this query may still depend on the number of node in the cluster, which indirectly depends on the amount of data stored. Nevertheless, the number of nodes will always be multiple number of magnitude lower than the number of user profile stored). Of course, both query may return very large result set in practice, but the amount of data returned can always be controlled by adding a LIMIT.', 1, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456,false )`)
- require.Nil(t.Test, err, fmt.Sprint(err))
- _, _, err = t.g.Query(`insert into /test/basic (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('3', '{
- "id": "omdb-query-query",
- "bid": "omdb-query-query",
- "type": "json-update",
- "data": {
- "message": [
- {
- "graph": {
- "nodes": [
- {
- "_icon": "app",
- "class": "/matrix/entity/app",
- "id": "app:demoapp3",
- "name": "app:demoapp3",
- "status": 5
- },
- {
- "class": "/matrix/entity/pod",
- "id": "pod:web-demo-f6dsp"
- },
- {
- "_icon": "mysql",
- "class": "/matrix/entity/mysql",
- "id": "mysql:demodb",
- "name": "mysql:demodb",
- "status": 0
- },
- {
- "_icon": "biz",
- "class": "/matrix/entity/biz",
- "id": "biz:开发测试",
- "name": "biz:开发测试",
- "status": 4
- },
- {
- "_icon": "linux",
- "class": "/matrix/entity/linux",
- "id": "linux:node2",
- "name": "linux:node2",
- "status": 0
- },
- {
- "_icon": "mysql",
- "class": "/matrix/entity/mysql",
- "id": "mysql:appdb",
- "name": "mysql:appdb",
- "status": 0
- },
- {
- "_icon": "app",
- "class": "/matrix/entity/app",
- "id": "app:demoapp2",
- "name": "app:demoapp2",
- "status": 0
- },
- {
- "_icon": "app",
- "class": "/matrix/entity/app",
- "id": "app:tomcat-app3",
- "name": "app:tomcat-app3",
- "status": 5
- },
- {
- "_icon": "linux",
- "class": "/matrix/entity/linux",
- "id": "linux:node1",
- "name": "linux:node1",
- "status": 0
- },
- {
- "_icon": "pod",
- "class": "/matrix/entity/pod",
- "id": "pod:tomcat-pod1",
- "name": "pod:tomcat-pod1",
- "status": 4
- },
- {
- "_icon": "linux",
- "class": "/matrix/entity/linux",
- "id": "linux:node4",
- "name": "linux:node4",
- "status": 0
- },
- {
- "_icon": "app",
- "class": "/matrix/entity/app",
- "id": "app:demoapp1",
- "name": "app:demoapp1",
- "status": 0
- },
- {
- "_icon": "pod",
- "class": "/matrix/entity/pod",
- "id": "pod:mysql-demo-pod1",
- "name": "pod:mysql-demo-pod1",
- "status": 4
- },
- {
- "_icon": "pod",
- "class": "/matrix/entity/pod",
- "id": "pod:tomcat-pod2",
- "name": "pod:tomcat-pod2",
- "status": 4
- },
- {
- "class": "/matrix/entity/pod",
- "id": "pod:tomcat-pod3"
- },
- {
- "_icon": "app",
- "class": "/matrix/entity/app",
- "id": "app:tomcat-app1",
- "name": "app:tomcat-app1",
- "status": 0
- },
- {
- "_icon": "app",
- "class": "/matrix/entity/app",
- "id": "app:tomcat-app2",
- "name": "app:tomcat-app2",
- "status": 0
- },
- {
- "class": "/matrix/entity/pod",
- "id": "pod:web-demo-j6qxj"
- },
- {
- "class": "/matrix/entity/pod",
- "id": "pod:web-demo-9rfxj"
- },
- {
- "_icon": "biz",
- "class": "/matrix/entity/biz",
- "id": "biz:数字国网",
- "name": "biz:数字国网",
- "status": 4
- }
- ],
- "edges": [
- {
- "attrs": {},
- "class": "connect",
- "id": "app:demoapp1-mysql:demodb",
- "source": "app:demoapp1",
- "target": "mysql:demodb"
- },
- {
- "attrs": {},
- "class": "contain",
- "id": "biz:开发测试-app:demoapp2",
- "source": "biz:开发测试",
- "target": "app:demoapp2"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "mysql:appdb-linux:node4",
- "source": "mysql:appdb",
- "target": "linux:node4"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "mysql:demodb-pod:mysql",
- "source": "mysql:demodb",
- "target": "pod:mysql"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "app:tomcat-app2",
- "source": "app:tomcat",
- "target": "app2"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "pod:tomcat-pod2",
- "source": "pod:tomcat",
- "target": "pod2"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "app:demoapp1-pod:web",
- "source": "app:demoapp1",
- "target": "pod:web"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "pod:mysql-demo",
- "source": "pod:mysql",
- "target": "demo"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "app:demoapp2-pod:web",
- "source": "app:demoapp2",
- "target": "pod:web"
- },
- {
- "attrs": {},
- "class": "connect",
- "id": "app:demoapp3-mysql:demodb",
- "source": "app:demoapp3",
- "target": "mysql:demodb"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "app:demoapp3-pod:web",
- "source": "app:demoapp3",
- "target": "pod:web"
- },
- {
- "attrs": {
- "floatp": 3.4,
- "intp": 1
- },
- "class": "contain",
- "id": "biz:数字国网-app:tomcat",
- "source": "biz:数字国网",
- "target": "app:tomcat"
- },
- {
- "attrs": {},
- "class": "connect",
- "id": "app:tomcat-app3",
- "source": "app:tomcat",
- "target": "app3"
- },
- {
- "attrs": {},
- "class": "contain",
- "id": "biz:开发测试-app:demoapp3",
- "source": "biz:开发测试",
- "target": "app:demoapp3"
- },
- {
- "attrs": {},
- "class": "contain",
- "id": "biz:开发测试-app:demoapp1",
- "source": "biz:开发测试",
- "target": "app:demoapp1"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "pod:tomcat-pod1",
- "source": "pod:tomcat",
- "target": "pod1"
- },
- {
- "attrs": {},
- "class": "connect",
- "id": "app:tomcat-app1",
- "source": "app:tomcat",
- "target": "app1"
- },
- {
- "attrs": {},
- "class": "connect",
- "id": "app:demoapp2-mysql:demodb",
- "source": "app:demoapp2",
- "target": "mysql:demodb"
- }
- ],
- "paths": null,
- "diff": null,
- "pathtags": null
- }
- }
- ],
- "meta": {
- "type": "graph"
- },
- "status": "ok"
- }
- }', 1, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456, true )`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- require.Nil(t.Test, err, fmt.Sprint(err))
- }
- func (t *BasicTests) Data2() {
- var err error
- _, _, err = t.g.Query(`insert into /test/basic2 (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool, v_blob) values ('*abc*', 'hello word 2003 123-456-789 中华人民共和国是中国的唯一合法政府,台湾是中国一部分。 Mercury, Venus2,Earch%。Mars$Uranus CeresAndJupiterOrSaturn #Neptune Pluto_Charon"\""', 5, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456, true, "hello" )`)
- require.Nil(t.Test, err, fmt.Sprint(err))
- //reinsert
- _, _, err = t.g.Query(`insert into /test/basic2 (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('*abc*', 'hello word 2003 123-456-789 中华人民共和国是中国的唯一合法政府,台湾是中国一部分。 Mercury, Venus2,Earch%。Mars$Uranus CeresAndJupiterOrSaturn #Neptune Pluto_Charon"\""', 1, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456, true )`)
- require.Nil(t.Test, err, fmt.Sprint(err))
- //_, _, err = t.g.Query(`insert into /test/basic2 (name) values ('hello')`)
- require.Nil(t.Test, err, fmt.Sprint(err))
- _, _, err = t.g.Query(`insert into /test/basic2 (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('2', 'because in both case, Cassandra guarantees that these queries performance will be proportional to the amount of data returned. In particular, if no users are born in 1981, then the second query performance will not depend of the number of user profile stored in the database (not directly at least: due to secondary index implementation consideration, this query may still depend on the number of node in the cluster, which indirectly depends on the amount of data stored. Nevertheless, the number of nodes will always be multiple number of magnitude lower than the number of user profile stored). Of course, both query may return very large result set in practice, but the amount of data returned can always be controlled by adding a LIMIT.', 1, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456,false )`)
- require.Nil(t.Test, err, fmt.Sprint(err))
- _, _, err = t.g.Query(`insert into /test/basic2 (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('3', '{
- "id": "omdb-query-query",
- "bid": "omdb-query-query",
- "type": "json-update",
- "data": {
- "message": [
- {
- "graph": {
- "nodes": [
- {
- "_icon": "app",
- "class": "/matrix/entity/app",
- "id": "app:demoapp3",
- "name": "app:demoapp3",
- "status": 5
- },
- {
- "class": "/matrix/entity/pod",
- "id": "pod:web-demo-f6dsp"
- },
- {
- "_icon": "mysql",
- "class": "/matrix/entity/mysql",
- "id": "mysql:demodb",
- "name": "mysql:demodb",
- "status": 0
- },
- {
- "_icon": "biz",
- "class": "/matrix/entity/biz",
- "id": "biz:开发测试",
- "name": "biz:开发测试",
- "status": 4
- },
- {
- "_icon": "linux",
- "class": "/matrix/entity/linux",
- "id": "linux:node2",
- "name": "linux:node2",
- "status": 0
- },
- {
- "_icon": "mysql",
- "class": "/matrix/entity/mysql",
- "id": "mysql:appdb",
- "name": "mysql:appdb",
- "status": 0
- },
- {
- "_icon": "app",
- "class": "/matrix/entity/app",
- "id": "app:demoapp2",
- "name": "app:demoapp2",
- "status": 0
- },
- {
- "_icon": "app",
- "class": "/matrix/entity/app",
- "id": "app:tomcat-app3",
- "name": "app:tomcat-app3",
- "status": 5
- },
- {
- "_icon": "linux",
- "class": "/matrix/entity/linux",
- "id": "linux:node1",
- "name": "linux:node1",
- "status": 0
- },
- {
- "_icon": "pod",
- "class": "/matrix/entity/pod",
- "id": "pod:tomcat-pod1",
- "name": "pod:tomcat-pod1",
- "status": 4
- },
- {
- "_icon": "linux",
- "class": "/matrix/entity/linux",
- "id": "linux:node4",
- "name": "linux:node4",
- "status": 0
- },
- {
- "_icon": "app",
- "class": "/matrix/entity/app",
- "id": "app:demoapp1",
- "name": "app:demoapp1",
- "status": 0
- },
- {
- "_icon": "pod",
- "class": "/matrix/entity/pod",
- "id": "pod:mysql-demo-pod1",
- "name": "pod:mysql-demo-pod1",
- "status": 4
- },
- {
- "_icon": "pod",
- "class": "/matrix/entity/pod",
- "id": "pod:tomcat-pod2",
- "name": "pod:tomcat-pod2",
- "status": 4
- },
- {
- "class": "/matrix/entity/pod",
- "id": "pod:tomcat-pod3"
- },
- {
- "_icon": "app",
- "class": "/matrix/entity/app",
- "id": "app:tomcat-app1",
- "name": "app:tomcat-app1",
- "status": 0
- },
- {
- "_icon": "app",
- "class": "/matrix/entity/app",
- "id": "app:tomcat-app2",
- "name": "app:tomcat-app2",
- "status": 0
- },
- {
- "class": "/matrix/entity/pod",
- "id": "pod:web-demo-j6qxj"
- },
- {
- "class": "/matrix/entity/pod",
- "id": "pod:web-demo-9rfxj"
- },
- {
- "_icon": "biz",
- "class": "/matrix/entity/biz",
- "id": "biz:数字国网",
- "name": "biz:数字国网",
- "status": 4
- }
- ],
- "edges": [
- {
- "attrs": {},
- "class": "connect",
- "id": "app:demoapp1-mysql:demodb",
- "source": "app:demoapp1",
- "target": "mysql:demodb"
- },
- {
- "attrs": {},
- "class": "contain",
- "id": "biz:开发测试-app:demoapp2",
- "source": "biz:开发测试",
- "target": "app:demoapp2"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "mysql:appdb-linux:node4",
- "source": "mysql:appdb",
- "target": "linux:node4"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "mysql:demodb-pod:mysql",
- "source": "mysql:demodb",
- "target": "pod:mysql"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "app:tomcat-app2",
- "source": "app:tomcat",
- "target": "app2"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "pod:tomcat-pod2",
- "source": "pod:tomcat",
- "target": "pod2"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "app:demoapp1-pod:web",
- "source": "app:demoapp1",
- "target": "pod:web"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "pod:mysql-demo",
- "source": "pod:mysql",
- "target": "demo"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "app:demoapp2-pod:web",
- "source": "app:demoapp2",
- "target": "pod:web"
- },
- {
- "attrs": {},
- "class": "connect",
- "id": "app:demoapp3-mysql:demodb",
- "source": "app:demoapp3",
- "target": "mysql:demodb"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "app:demoapp3-pod:web",
- "source": "app:demoapp3",
- "target": "pod:web"
- },
- {
- "attrs": {
- "floatp": 3.4,
- "intp": 1
- },
- "class": "contain",
- "id": "biz:数字国网-app:tomcat",
- "source": "biz:数字国网",
- "target": "app:tomcat"
- },
- {
- "attrs": {},
- "class": "connect",
- "id": "app:tomcat-app3",
- "source": "app:tomcat",
- "target": "app3"
- },
- {
- "attrs": {},
- "class": "contain",
- "id": "biz:开发测试-app:demoapp3",
- "source": "biz:开发测试",
- "target": "app:demoapp3"
- },
- {
- "attrs": {},
- "class": "contain",
- "id": "biz:开发测试-app:demoapp1",
- "source": "biz:开发测试",
- "target": "app:demoapp1"
- },
- {
- "attrs": {},
- "class": "runon",
- "id": "pod:tomcat-pod1",
- "source": "pod:tomcat",
- "target": "pod1"
- },
- {
- "attrs": {},
- "class": "connect",
- "id": "app:tomcat-app1",
- "source": "app:tomcat",
- "target": "app1"
- },
- {
- "attrs": {},
- "class": "connect",
- "id": "app:demoapp2-mysql:demodb",
- "source": "app:demoapp2",
- "target": "mysql:demodb"
- }
- ],
- "paths": null,
- "diff": null,
- "pathtags": null
- }
- }
- ],
- "meta": {
- "type": "graph"
- },
- "status": "ok"
- }
- }', 1, 1234567890123456789, 1.1, 1.1234567890123456, 1.123456, true )`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- require.Nil(t.Test, err, fmt.Sprint(err))
- }
- func (t *BasicTests) Valid() {
- rtn, _, err := t.g.Query(`select * from /test/basic refresh`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, 3, len(rtn), "they should be equal")
- for _, row := range rtn {
- switch row["v_varchar"].(string) {
- case "*abc*":
- assert.Equal(t.Test, `hello word 2003 123-456-789 中华人民共和国是中国的唯一合法政府,台湾是中国一部分。 Mercury, Venus2,Earch%。Mars$Uranus CeresAndJupiterOrSaturn #Neptune Pluto_Charon"\""`, row["v_text"].(string), "they should be equal")
- }
- }
- }
- }
- rtn, _, err = t.g.Query(` select * from /test/basic where v_varchar=='*abc*' `)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, 1, len(rtn), "they should be equal")
- }
- }
- rtn, _, err = t.g.Query(`select * from / where v_varchar=='*abc*' `)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- count := 0
- for _, m := range rtn {
- v := m["class"]
- if c, ok := v.(string); ok && c == "/test/basic" {
- count++
- }
- }
- assert.Equal(t.Test, 1, count, "they should be equal")
- }
- rtn, _, err = t.g.Query(`select * from /test/ where v_varchar=='*abc*' `)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- count := 0
- for _, m := range rtn {
- v := m["class"]
- if c, ok := v.(string); ok && c == "/test/basic" {
- count++
- }
- }
- assert.Equal(t.Test, 1, count, "they should be equal")
- }
- }
- func (t *BasicTests) Valid2() {
- rtn, _, err := t.g.Query(`select * from /test/basic2`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if false {
- bs, _ := json.MarshalIndent(rtn, "", " ")
- fmt.Println("/test/basic2 data:\n", string(bs))
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, 3, len(rtn), "they should be equal")
- for _, row := range rtn {
- switch row["v_varchar"].(string) {
- case "*abc*":
- assert.Equal(t.Test, `hello word 2003 123-456-789 中华人民共和国是中国的唯一合法政府,台湾是中国一部分。 Mercury, Venus2,Earch%。Mars$Uranus CeresAndJupiterOrSaturn #Neptune Pluto_Charon"\""`, row["v_text"].(string), "they should be equal")
- }
- }
- }
- }
- rtn, _, err = t.g.Query(` select * from /test/basic2 where v_varchar=='*abc*' `)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, 1, len(rtn), "they should be equal")
- }
- }
- // 内存库延迟持久化写入 1s + cassandra索引延迟 1s + cassandra分布式数据同步 1s
- time.Sleep(3 * time.Second)
- rtn, _, err = t.g.Query(`select * from / where v_varchar=='*abc*' `)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- count := 0
- for _, m := range rtn {
- v := m["class"]
- if c, ok := v.(string); ok && (c == "/test/basic" || c == "/test/basic2") {
- count++
- }
- }
- assert.Equal(t.Test, 2, count, "they should be equal")
- }
- rtn, _, err = t.g.Query(`select * from /test/ where v_varchar=='*abc*' `)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- count := 0
- for _, m := range rtn {
- v := m["class"]
- if c, ok := v.(string); ok && (c == "/test/basic" || c == "/test/basic2") {
- count++
- }
- }
- assert.Equal(t.Test, 2, count, "they should be equal")
- }
- }
- func (t *BasicTests) Int() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select * from /test/basic where v_int = 1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int = %v", "1"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_int > 0`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int > %v", "0"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_int < 2`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int < %v", "2"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_int >= 1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int >= %v", "1"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_int <= 1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int <= %v", "1"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_int >= 1.1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 0, len(rtn), fmt.Sprintf("not find v_int >= %v", "1.1"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_int > 1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 0, len(rtn), fmt.Sprintf("not find v_int > %v", "1"))
- }
- }
- func (t *BasicTests) Int2() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_int = 1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int = %v", "1"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_int > 0`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int > %v", "0"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_int < 2`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int < %v", "2"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_int >= 1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int >= %v", "1"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_int <= 1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_int <= %v", "1"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_int >= 1.1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 0, len(rtn), fmt.Sprintf("not find v_int >= %v", "1.1"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_int > 1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 0, len(rtn), fmt.Sprintf("not find v_int > %v", "1"))
- }
- }
- func (t *BasicTests) Bool() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select * from /test/basic where v_bool = true`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 2, len(rtn), fmt.Sprintf("not find v_bool = %v", "true"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_bool = false`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find v_bool = %v", "false"))
- }
- }
- func (t *BasicTests) Bool2() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_bool = true`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 2, len(rtn), fmt.Sprintf("not find v_bool = %v", "true"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_bool = false`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find v_bool = %v", "false"))
- }
- }
- func (t *BasicTests) Float() {
- var err error
- var rtn []map[string]interface{}
- var allfalse = false
- rtn, _, err = t.g.Query(`select * from /test/basic where v_float >= 1.1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- allfalse = allfalse || assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float >= %v", "1.1"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_float > 1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- allfalse = allfalse || assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float > %v", "1"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_float = 1.1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- allfalse = allfalse || assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float = %v", "1.1"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_float < 2`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- allfalse = allfalse || assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float < %v", "2"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_float <= 1.1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- allfalse = allfalse || assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float <= %v", "1.1"))
- }
- if allfalse == false {
- assert.Nil(t.Test, "浮点数怎么判断都不对,重启cassandra试试")
- }
- }
- func (t *BasicTests) Float2() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_float >= 1.1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float >= %v", "1.1"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_float > 1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float > %v", "1"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_float = 1.1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float = %v", "1.1"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_float < 2`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float < %v", "2"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_float <= 1.1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_float <= %v", "1.1"))
- }
- }
- func (t *BasicTests) Double() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select * from /test/basic where v_double >= 1.1234567890123456`)
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_double >= %v", "1.1234567890123456"))
- }
- //??????
- rtn, _, err = t.g.Query(`select * from /test/basic where v_smalldouble >= 1.123456`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find , v_smalldouble >= %v", "1.123456"))
- }
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_double > 1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_double > %v", "1"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_double = 1.1234567890123456`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.NotEqual(t.Test, int64(3), len(rtn), fmt.Sprintf("not find v_double = %v", "1.1234567890123456"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_double < 2`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_double < %v", "2"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_double <= 1.1234567890123456`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_double <= %v", "1.1234567890123456"))
- }
- }
- func (t *BasicTests) Double2() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_double >= 1.1234567890123456`)
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_double >= %v", "1.1234567890123456"))
- }
- //??????
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_smalldouble >= 1.123456`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- if assert.NotNil(t.Test, rtn) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find , v_smalldouble >= %v", "1.123456"))
- }
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_double > 1`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_double > %v", "1"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_double = 1.1234567890123456`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.NotEqual(t.Test, int64(3), len(rtn), fmt.Sprintf("not find v_double = %v", "1.1234567890123456"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_double < 2`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_double < %v", "2"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_double <= 1.1234567890123456`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("not find v_double <= %v", "1.1234567890123456"))
- }
- }
- func (t *BasicTests) NotIn() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select * from /test/basic where v_varchar not in('2', '3')`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "hello"))
- }
- }
- func (t *BasicTests) NotIn2() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_varchar not in('2', '3')`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "hello"))
- }
- }
- func (t *BasicTests) Prefix() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select * from /test/basic where v_text=^'hell'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "hello"))
- }
- rtn, _, err = t.g.Query(`select *from /test/basic where v_text='*20*'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "2003"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_text='*123-456*'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "123-456-789"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_text='*中*'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "中国"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_text='*magni*'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "magnitude"))
- }
- }
- func (t *BasicTests) Prefix2() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_text=^'hell'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "hello"))
- }
- rtn, _, err = t.g.Query(`select *from /test/basic2 where v_text='*20*'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "2003"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_text='*123-456*'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "123-456-789"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_text='*中*'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "中国"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_text='*magni*'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "magnitude"))
- }
- }
- func (t *BasicTests) FullSearch() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select * from /test/basic where v_text='hello'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "hello"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_text='2003'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "2003"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_text='123-456-789'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "123-456-789"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_text='中国'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "中国"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic where v_text='magnitude'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "magnitude"))
- }
- }
- func (t *BasicTests) FullSearch2() {
- var err error
- var rtn []map[string]interface{}
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_text='hello'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "hello"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_text='2003'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "2003"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_text='123-456-789'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "123-456-789"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_text='中国'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "中国"))
- }
- rtn, _, err = t.g.Query(`select * from /test/basic2 where v_text='magnitude'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 1, len(rtn), fmt.Sprintf("not find %v", "magnitude"))
- }
- }
- func (t *BasicTests) Aggr() {
- var err error
- var rtn []map[string]interface{}
- _, _, err = t.g.Query(`insert into /test/basic (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('2', 'hhhhhh', 1, 1534567890123456789, 1.3, 2.1234567890123456, 1.223456, true )`)
- rtn, _, err = t.g.Query(`select count(*) from /test/basic group by v_varchar`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("count group by %v", "varchar"))
- }
- rtn, _, err = t.g.Query(`select sum(v_float), min(v_int), max(v_double) , avg(v_int) as avgint, v_varchar from /test/basic group by v_varchar`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("agr group by %v", "varchar"))
- }
- }
- func (t *BasicTests) Aggr2() {
- var err error
- var rtn []map[string]interface{}
- _, _, err = t.g.Query(`insert into /test/basic2 (v_varchar, v_text, v_int, v_bigint, v_float, v_double, v_smalldouble, v_bool) values ('2', 'hhhhhh', 1, 1534567890123456789, 1.3, 2.1234567890123456, 1.223456, true )`)
- rtn, _, err = t.g.Query(`select count(*) from /test/basic2 group by v_varchar`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("count group by %v", "varchar"))
- }
- rtn, _, err = t.g.Query(`select sum(v_float), min(v_int), max(v_double) , avg(v_int) as avgint, v_varchar from /test/basic2 group by v_varchar`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- assert.Equal(t.Test, 3, len(rtn), fmt.Sprintf("agr group by %v", "varchar"))
- }
- }
- func (t *BasicTests) PrivateField() {
- //rtn, _, err := t.g.Query(`select class from /system/field where name='basic:target'`)
- _, _, err := t.g.Query(`select class from /system/field where namespace='test' and name='basic:target'`)
- if err != nil {
- logger.Errorf("%v", err)
- }
- if assert.Nil(t.Test, err) {
- //assert.Equal(t.Test, 2, len(rtn[0]["class"].([]int)), fmt.Sprintf("private field should 2"))
- }
- }
|