| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package logs | 5 package logs |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "sort" | 9 "sort" |
| 10 "testing" | 10 "testing" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 "name": string(name), | 146 "name": string(name), |
| 147 } | 147 } |
| 148 | 148 |
| 149 // Set an empty tag for each name segment. | 149 // Set an empty tag for each name segment. |
| 150 for _, p := range name.Segments() { | 150 for _, p := range name.Segments() { |
| 151 desc.Tags[p] = "" | 151 desc.Tags[p] = "" |
| 152 } | 152 } |
| 153 | 153 |
| 154 ls := ct.TestLogStream(c, desc) | 154 ls := ct.TestLogStream(c, desc) |
| 155 | 155 |
| 156 now := tc.Now().UTC() |
| 156 psegs := prefix.Segments() | 157 psegs := prefix.Segments() |
| 157 if psegs[0] == "meta" { | 158 if psegs[0] == "meta" { |
| 158 for _, p := range psegs[1:] { | 159 for _, p := range psegs[1:] { |
| 159 switch p { | 160 switch p { |
| 160 case "purged": | 161 case "purged": |
| 161 ls.Purged = true | 162 ls.Purged = true |
| 162 | 163 |
| 163 case "terminated": | 164 case "terminated": |
| 164 ls.State = coordinator.LSTermina
ted | |
| 165 ls.TerminalIndex = 1337 | 165 ls.TerminalIndex = 1337 |
| 166 ls.TerminatedTime = now |
| 166 | 167 |
| 167 case "archived": | 168 case "archived": |
| 169 ls.State = coordinator.LSArchive
d |
| 170 |
| 171 ls.TerminalIndex = 1337 |
| 172 ls.TerminatedTime = now |
| 173 |
| 168 ls.ArchiveStreamURL = "http://ex
ample.com" | 174 ls.ArchiveStreamURL = "http://ex
ample.com" |
| 169 » » » » » » ls.State = coordinator.LSArchive
d | 175 » » » » » » ls.ArchivedTime = now |
| 170 | 176 |
| 171 case "datagram": | 177 case "datagram": |
| 172 ls.StreamType = logpb.StreamType
_DATAGRAM | 178 ls.StreamType = logpb.StreamType
_DATAGRAM |
| 173 | 179 |
| 174 case "binary": | 180 case "binary": |
| 175 ls.StreamType = logpb.StreamType
_BINARY | 181 ls.StreamType = logpb.StreamType
_BINARY |
| 176 } | 182 } |
| 177 } | 183 } |
| 178 } | 184 } |
| 179 | 185 |
| 180 » » » if err := ls.Put(ds.Get(c)); err != nil { | 186 » » » if err := ds.Get(c).Put(ls); err != nil { |
| 181 panic(fmt.Errorf("failed to put log stream %d: %
v", i, err)) | 187 panic(fmt.Errorf("failed to put log stream %d: %
v", i, err)) |
| 182 } | 188 } |
| 183 | 189 |
| 184 descs[string(v)] = desc | 190 descs[string(v)] = desc |
| 185 streams[string(v)] = ls | 191 streams[string(v)] = ls |
| 186 if !ls.Purged { | 192 if !ls.Purged { |
| 187 streamPaths = append(streamPaths, string(v)) | 193 streamPaths = append(streamPaths, string(v)) |
| 188 } | 194 } |
| 189 purgedStreamPaths = append(purgedStreamPaths, string(v)) | 195 purgedStreamPaths = append(purgedStreamPaths, string(v)) |
| 190 tc.Add(time.Second) | 196 tc.Add(time.Second) |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 So(err, ShouldBeRPCOK) | 269 So(err, ShouldBeRPCOK) |
| 264 So(resp, shouldHaveLogPaths, "testing/+/
baz") | 270 So(resp, shouldHaveLogPaths, "testing/+/
baz") |
| 265 | 271 |
| 266 So(resp.Streams, ShouldHaveLength, 1) | 272 So(resp.Streams, ShouldHaveLength, 1) |
| 267 So(resp.Streams[0].State, ShouldResemble
, loadLogStreamState(stream)) | 273 So(resp.Streams[0].State, ShouldResemble
, loadLogStreamState(stream)) |
| 268 So(resp.Streams[0].Desc, ShouldResemble,
desc) | 274 So(resp.Streams[0].Desc, ShouldResemble,
desc) |
| 269 So(resp.Streams[0].DescProto, ShouldBeNi
l) | 275 So(resp.Streams[0].DescProto, ShouldBeNi
l) |
| 270 }) | 276 }) |
| 271 | 277 |
| 272 Convey(`When not requesting protobufs, and with
a corrupt descriptor, returns InternalServer error.`, func() { | 278 Convey(`When not requesting protobufs, and with
a corrupt descriptor, returns InternalServer error.`, func() { |
| 273 » » » » » // We can't use "stream.Put" here becaus
e it validates the protobuf! | 279 » » » » » stream.SetDSValidate(false) |
| 274 stream.Descriptor = []byte{0x00} // Inva
lid protobuf, zero tag. | 280 stream.Descriptor = []byte{0x00} // Inva
lid protobuf, zero tag. |
| 275 So(di.Put(stream), ShouldBeNil) | 281 So(di.Put(stream), ShouldBeNil) |
| 276 di.Testable().CatchupIndexes() | 282 di.Testable().CatchupIndexes() |
| 277 | 283 |
| 278 _, err := s.Query(c, &req) | 284 _, err := s.Query(c, &req) |
| 279 So(err, ShouldBeRPCInternal) | 285 So(err, ShouldBeRPCInternal) |
| 280 }) | 286 }) |
| 281 | 287 |
| 282 Convey(`When requesting protobufs, returns the r
aw protobuf descriptor.`, func() { | 288 Convey(`When requesting protobufs, returns the r
aw protobuf descriptor.`, func() { |
| 283 req.Proto = true | 289 req.Proto = true |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 | 510 |
| 505 Convey(`When an invalid tag is specified, returns BadReq
uest error`, func() { | 511 Convey(`When an invalid tag is specified, returns BadReq
uest error`, func() { |
| 506 req.Tags["+++not a valid tag+++"] = "" | 512 req.Tags["+++not a valid tag+++"] = "" |
| 507 | 513 |
| 508 _, err := s.Query(c, &req) | 514 _, err := s.Query(c, &req) |
| 509 So(err, ShouldBeRPCInvalidArgument, "invalid tag
constraint") | 515 So(err, ShouldBeRPCInvalidArgument, "invalid tag
constraint") |
| 510 }) | 516 }) |
| 511 }) | 517 }) |
| 512 }) | 518 }) |
| 513 } | 519 } |
| OLD | NEW |