github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/pkg/influx/writer/putmetrics_test.go (about)

     1  /*
     2  Copyright 2023.
     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  package writer
    18  
    19  import (
    20  	"os"
    21  	"sync/atomic"
    22  	"testing"
    23  	"time"
    24  
    25  	"github.com/siglens/siglens/pkg/config"
    26  	"github.com/siglens/siglens/pkg/segment/writer"
    27  	log "github.com/sirupsen/logrus"
    28  	"github.com/stretchr/testify/assert"
    29  )
    30  
    31  var rawCSV = []byte("measurement,tag1=val1,tag2=val2 value=100 0000000000000000000\nmeasurement,tag1=val1,tag2=val2 value=300 0000000000000000000\n")
    32  
    33  func Test_InsertCsv(t *testing.T) {
    34  
    35  	config.InitializeTestingConfig()
    36  	writer.InitWriterNode()
    37  
    38  	sTime := time.Now()
    39  	totalSuccess := uint64(0)
    40  	for i := 0; i < 100; i++ {
    41  		success, fail, err := HandlePutMetrics([]byte(rawCSV), 0)
    42  		assert.NoError(t, err)
    43  		assert.Equal(t, success, uint64(2))
    44  		assert.Equal(t, fail, uint64(0))
    45  		atomic.AddUint64(&totalSuccess, success)
    46  
    47  	}
    48  	log.Infof("Ingested %+v metrics in %+v", totalSuccess, time.Since(sTime))
    49  	err := os.RemoveAll(config.GetDataPath())
    50  	assert.NoError(t, err)
    51  
    52  }