github.com/rohankumardubey/aresdb@v0.0.2-0.20190517170215-e54e3ca06b9c/diskstore/diskstore_util_test.go (about)

     1  //  Copyright (c) 2017-2018 Uber Technologies, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package diskstore
    16  
    17  import (
    18  	"fmt"
    19  
    20  	"github.com/onsi/ginkgo"
    21  	. "github.com/onsi/gomega"
    22  )
    23  
    24  var _ = ginkgo.Describe("DiskStoreUtils", func() {
    25  	var path string
    26  	ginkgo.It("Test General Utils", func() {
    27  		path = getPathForTableShard("/path/to/store", "myTable", 1)
    28  		Ω(path).Should(Equal("/path/to/store/data/myTable_1"))
    29  		path = getPathForTableShard("/path/to/store/", "myTable", 1)
    30  		Ω(path).Should(Equal("/path/to/store/data/myTable_1"))
    31  		path = getPathForTableShard("", "myTable", 1)
    32  		Ω(path).Should(Equal("data/myTable_1"))
    33  	})
    34  
    35  	ginkgo.It("Test Redolog Utils", func() {
    36  		path = GetPathForTableRedologs("/path/to/store/", "myTable", 1)
    37  		Ω(path).Should(Equal(fmt.Sprintf("/path/to/store/data/myTable_1/redologs")))
    38  		path = GetPathForRedologFile("/path/to/store/", "myTable", 1, 1500496811)
    39  		Ω(path).Should(Equal(fmt.Sprintf("/path/to/store/data/myTable_1/redologs/1500496811.redolog")))
    40  	})
    41  
    42  	ginkgo.It("Test Snapshot Utils", func() {
    43  		path = GetPathForTableSnapshotDir("/path/to/store/", "myTable", 1)
    44  		Ω(path).Should(Equal(fmt.Sprintf("/path/to/store/data/myTable_1/snapshots")))
    45  		path = GetPathForTableSnapshotDirPath("/path/to/store/", "myTable", 1, 12345, 123)
    46  		Ω(path).Should(Equal(fmt.Sprintf("/path/to/store/data/myTable_1/snapshots/12345_123")))
    47  	})
    48  
    49  	ginkgo.It("Test Archive batch Utils", func() {
    50  		path = GetPathForTableArchiveBatchRootDir("/path/to/store/", "myTable", 1)
    51  		Ω(path).Should(Equal(fmt.Sprintf("/path/to/store/data/myTable_1/archiving_batches")))
    52  		path = GetPathForTableArchiveBatchDir("/path/to/store/", "myTable", 1, "2017-07-19", 1499970253, 0)
    53  		Ω(path).Should(Equal(fmt.Sprintf("/path/to/store/data/myTable_1/archiving_batches/2017-07-19_1499970253")))
    54  		path = GetPathForTableArchiveBatchColumnFile("/path/to/store/", "myTable", 1, "2017-07-19", 1499970253, 0, 100)
    55  		Ω(path).Should(Equal(fmt.Sprintf("/path/to/store/data/myTable_1/archiving_batches/2017-07-19_1499970253/100.data")))
    56  	})
    57  
    58  	ginkgo.It("Test ParseBatchIDAndVersionName Utils", func() {
    59  		// make sure it's backward compatible: seq number does not exist
    60  		batchID, batchVersion, seqNum, err := ParseBatchIDAndVersionName("2017-07-19_1499970253")
    61  		Ω(batchID).Should(Equal("2017-07-19"))
    62  		Ω(batchVersion).Should(Equal(uint32(1499970253)))
    63  		Ω(seqNum).Should(Equal(uint32(0)))
    64  		Ω(err).Should(BeNil())
    65  		// seq num exists
    66  		batchID, batchVersion, seqNum, err = ParseBatchIDAndVersionName("2017-07-19_1499970253-3")
    67  		Ω(batchID).Should(Equal("2017-07-19"))
    68  		Ω(batchVersion).Should(Equal(uint32(1499970253)))
    69  		Ω(seqNum).Should(Equal(uint32(3)))
    70  		Ω(err).Should(BeNil())
    71  		batchID, batchVersion, seqNum, err = ParseBatchIDAndVersionName("2017-07-191499970253")
    72  		Ω(err).ShouldNot(BeNil())
    73  		batchID, batchVersion, seqNum, err = ParseBatchIDAndVersionName("2017-07-19_xxx")
    74  		Ω(err).ShouldNot(BeNil())
    75  	})
    76  
    77  })