001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.mob; 019 020import static org.junit.jupiter.api.Assertions.assertEquals; 021import static org.junit.jupiter.api.Assertions.assertFalse; 022import static org.junit.jupiter.api.Assertions.assertNotSame; 023import static org.junit.jupiter.api.Assertions.assertTrue; 024 025import java.util.Date; 026import java.util.concurrent.ThreadLocalRandom; 027import org.apache.hadoop.hbase.HBaseTestingUtil; 028import org.apache.hadoop.hbase.testclassification.SmallTests; 029import org.apache.hadoop.hbase.util.Bytes; 030import org.apache.hadoop.hbase.util.MD5Hash; 031import org.junit.jupiter.api.BeforeEach; 032import org.junit.jupiter.api.Tag; 033import org.junit.jupiter.api.Test; 034 035@Tag(SmallTests.TAG) 036public class TestMobFileName { 037 038 private String uuid; 039 private Date date; 040 private String dateStr; 041 private byte[] startKey; 042 private String regionName = "region"; 043 044 @BeforeEach 045 public void setUp() { 046 uuid = HBaseTestingUtil.getRandomUUID().toString().replaceAll("-", ""); 047 date = new Date(); 048 dateStr = MobUtils.formatDate(date); 049 startKey = Bytes.toBytes(ThreadLocalRandom.current().nextInt()); 050 } 051 052 @Test 053 public void testHashCode() { 054 assertEquals(MobFileName.create(startKey, dateStr, uuid, regionName).hashCode(), 055 MobFileName.create(startKey, dateStr, uuid, regionName).hashCode()); 056 assertNotSame(MobFileName.create(startKey, dateStr, uuid, regionName), 057 MobFileName.create(startKey, dateStr, uuid, regionName)); 058 } 059 060 @Test 061 public void testCreate() { 062 MobFileName mobFileName = MobFileName.create(startKey, dateStr, uuid, regionName); 063 assertEquals(mobFileName, MobFileName.create(mobFileName.getFileName())); 064 } 065 066 @Test 067 public void testGet() { 068 MobFileName mobFileName = MobFileName.create(startKey, dateStr, uuid, regionName); 069 assertEquals(MD5Hash.getMD5AsHex(startKey, 0, startKey.length), mobFileName.getStartKey()); 070 assertEquals(dateStr, mobFileName.getDate()); 071 assertEquals(mobFileName.getFileName(), 072 MD5Hash.getMD5AsHex(startKey, 0, startKey.length) + dateStr + uuid + "_" + regionName); 073 } 074 075 @Test 076 public void testEquals() { 077 MobFileName mobFileName = MobFileName.create(startKey, dateStr, uuid, regionName); 078 assertTrue(mobFileName.equals(mobFileName)); 079 assertFalse(mobFileName.equals(this)); 080 assertTrue(mobFileName.equals(MobFileName.create(startKey, dateStr, uuid, regionName))); 081 } 082}