1+ /**
2+ * Copyright 2018 Google Inc. All Rights Reserved.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ import * as assert from 'assert' ;
18+ import * as mocha from 'mocha' ;
19+
20+ import { Buffer } from '../src/exporters/buffer' ;
21+ import { NoopExporter } from '../src/exporters/consolelog-exporter' ;
22+ import { RootSpanImpl } from '../src/trace/model/rootspan' ;
23+ import { TracerImpl } from '../src/trace/model/tracer' ;
24+
25+ const exporter = new NoopExporter ( ) ;
26+ const DEFAULT_BUFFER_SIZE = 3 ;
27+ const DEFAULT_BUFFER_TIMEOUT = 20000 ; // time in milliseconds
28+ const tracer = new TracerImpl ( ) ;
29+
30+
31+ describe ( 'Buffer' , ( ) => {
32+ /**
33+ * Should create a Buffer with exporter, DEFAULT_BUFFER_SIZE and
34+ * DEFAULT_BUFFER_TIMEOUT
35+ */
36+ describe ( 'new Buffer()' , ( ) => {
37+ it ( 'should create a Buffer instance' , ( ) => {
38+ const buffer =
39+ new Buffer ( exporter , DEFAULT_BUFFER_SIZE , DEFAULT_BUFFER_TIMEOUT ) ;
40+ assert . ok ( buffer instanceof Buffer ) ;
41+ } ) ;
42+ } ) ;
43+
44+ /**
45+ * Should return the Buffer
46+ */
47+ describe ( 'setBufferSize' , ( ) => {
48+ it ( 'should return the Buffer instance' , ( ) => {
49+ const buffer = new Buffer ( exporter ) ;
50+ const bufferResize = buffer . setBufferSize ( DEFAULT_BUFFER_SIZE ) ;
51+ assert . ok ( bufferResize instanceof Buffer ) ;
52+ } ) ;
53+ } ) ;
54+
55+ /**
56+ * Should return the Buffer with rootspan
57+ */
58+ describe ( 'addToBuffer' , ( ) => {
59+ it ( 'should return the Buffer instance' , ( ) => {
60+ const buffer = new Buffer ( exporter ) ;
61+ const rootSpan = new RootSpanImpl ( tracer ) ;
62+ const bufferAdd = buffer . addToBuffer ( rootSpan ) ;
63+ assert . ok ( bufferAdd instanceof Buffer ) ;
64+ } ) ;
65+ } ) ;
66+
67+ /**
68+ * Should return the Buffer without rootspan
69+ */
70+ describe ( 'addToBuffer force flush ' , ( ) => {
71+ it ( 'should return the Buffer instance' , ( ) => {
72+ const buffer = new Buffer ( exporter ) ;
73+ const bufferResize = buffer . setBufferSize ( 0 ) ;
74+ const rootSpan = new RootSpanImpl ( tracer ) ;
75+ const bufferAdd = bufferResize . addToBuffer ( rootSpan ) ;
76+ assert . ok ( bufferAdd instanceof Buffer ) ;
77+ } ) ;
78+ } ) ;
79+
80+ /**
81+ * Should return the Buffer without rootspan
82+ */
83+ describe ( 'addToBuffer force flush by timeout ' , ( ) => {
84+ it ( 'should return the Buffer instance' , ( ) => {
85+ const buffer = new Buffer ( exporter , DEFAULT_BUFFER_SIZE , 0 ) ;
86+ const rootSpan = new RootSpanImpl ( tracer ) ;
87+ let bufferAdd = buffer . addToBuffer ( rootSpan ) ;
88+ bufferAdd = buffer . addToBuffer ( rootSpan ) ;
89+ assert . ok ( bufferAdd instanceof Buffer ) ;
90+ } ) ;
91+ } ) ;
92+ } ) ;
0 commit comments