Apply .gitignore rules
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package remark
|
||||
|
||||
import (
|
||||
"goutil/logUtilPlus"
|
||||
)
|
||||
|
||||
var (
|
||||
remarksSlice []*ModuleRemark = make([]*ModuleRemark, 0, 32)
|
||||
)
|
||||
|
||||
// RegisterModuleRemark
|
||||
//
|
||||
// @description: 注册模块说明对象
|
||||
//
|
||||
// parameter:
|
||||
//
|
||||
// @name: 模块名称
|
||||
// @desc: 模块描述
|
||||
// @author: 模块作者
|
||||
// @mendor: 模块修改者(多个用,分隔)
|
||||
// @date: 创建日期
|
||||
//
|
||||
// return:
|
||||
func RegisterModuleRemark(name, desc, author, mendor, date string) {
|
||||
remarksSlice = append(remarksSlice, newModuleRemark(name, desc, author, mendor, date))
|
||||
}
|
||||
|
||||
// RegisterMethodRemark
|
||||
//
|
||||
// @description: 注册方法说明对象
|
||||
//
|
||||
// parameter:
|
||||
//
|
||||
// @moduleName: 模块名称
|
||||
// @name: 方法名称
|
||||
// @desc: 方法描述
|
||||
// @author: 方法作者
|
||||
// @mendor: 方法修改者(多个用,分隔)
|
||||
// @date: 创建日期
|
||||
// @inParam: 输入参数
|
||||
// @outParam: 输出参数
|
||||
//
|
||||
// return:
|
||||
func RegisterMethodRemark(moduleName, name, desc, author, mendor, date string, inParam []string, outParam string) {
|
||||
var moduleRemark *ModuleRemark
|
||||
var exists bool
|
||||
for _, item := range remarksSlice {
|
||||
if item.Name == moduleName {
|
||||
moduleRemark = item
|
||||
exists = true
|
||||
}
|
||||
}
|
||||
|
||||
if !exists {
|
||||
logUtilPlus.ErrorLog("ModuleRemark:%s尚未注册", moduleName)
|
||||
return
|
||||
}
|
||||
|
||||
moduleRemark.MethodRemarkSlice = append(moduleRemark.MethodRemarkSlice, newMethodRemark(moduleName, name, desc, author, mendor, date, inParam, outParam))
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package logUtil
|
||||
|
||||
type LogType int
|
||||
|
||||
// 日志等级
|
||||
const (
|
||||
// Info 信息
|
||||
Info LogType = iota
|
||||
|
||||
// Warn 警告
|
||||
Warn
|
||||
|
||||
// Debug 调试
|
||||
Debug
|
||||
|
||||
// Error 错误
|
||||
Error
|
||||
|
||||
// Fatal 致命
|
||||
Fatal
|
||||
)
|
||||
|
||||
// String
|
||||
// @description: 类型转化为字符串
|
||||
// parameter:
|
||||
// @receiver t:
|
||||
// return:
|
||||
// @string:
|
||||
func (t LogType) String() string {
|
||||
switch t {
|
||||
case Info:
|
||||
return "Info"
|
||||
case Warn:
|
||||
return "Warn"
|
||||
case Debug:
|
||||
return "Debug"
|
||||
case Error:
|
||||
return "Error"
|
||||
case Fatal:
|
||||
return "Fatal"
|
||||
}
|
||||
|
||||
return "LogTypeDefault"
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package syncUtil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestNewLocker1(t *testing.T) {
|
||||
count := 1000000
|
||||
succeedCount := 0
|
||||
expected := 1000000
|
||||
goroutineCount := 1
|
||||
|
||||
lockerObj := NewLocker()
|
||||
ch := make(chan bool, goroutineCount)
|
||||
|
||||
for i := 0; i < goroutineCount; i++ {
|
||||
go lockerTest(lockerObj, &succeedCount, count/goroutineCount, ch)
|
||||
}
|
||||
|
||||
for i := 0; i < goroutineCount; i++ {
|
||||
<-ch
|
||||
}
|
||||
|
||||
if succeedCount != expected {
|
||||
t.Errorf("Expected %d, but got %d", expected, succeedCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewLocker2(t *testing.T) {
|
||||
count := 1000000
|
||||
succeedCount := 0
|
||||
expected := 1000000
|
||||
goroutineCount := 100
|
||||
|
||||
lockerObj := NewLocker()
|
||||
ch := make(chan bool, goroutineCount)
|
||||
|
||||
for i := 0; i < goroutineCount; i++ {
|
||||
go lockerTest(lockerObj, &succeedCount, count/goroutineCount, ch)
|
||||
}
|
||||
|
||||
for i := 0; i < goroutineCount; i++ {
|
||||
<-ch
|
||||
}
|
||||
|
||||
if succeedCount != expected {
|
||||
t.Errorf("Expected %d, but got %d", expected, succeedCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewLocker3(t *testing.T) {
|
||||
count := 1000000
|
||||
succeedCount := 0
|
||||
expected := 1000000
|
||||
goroutineCount := 10000
|
||||
|
||||
lockerObj := NewLocker()
|
||||
ch := make(chan bool, goroutineCount)
|
||||
|
||||
for i := 0; i < goroutineCount; i++ {
|
||||
go lockerTest(lockerObj, &succeedCount, count/goroutineCount, ch)
|
||||
}
|
||||
|
||||
for i := 0; i < goroutineCount; i++ {
|
||||
<-ch
|
||||
}
|
||||
|
||||
if succeedCount != expected {
|
||||
t.Errorf("Expected %d, but got %d", expected, succeedCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewLocker4(t *testing.T) {
|
||||
lockerObj := NewLocker()
|
||||
if successful, _, _ := lockerObj.Lock(100); successful == false {
|
||||
t.Errorf("Lock should be successful, but now it fails.")
|
||||
}
|
||||
|
||||
if successful, _, _ := lockerObj.Lock(100); successful {
|
||||
t.Errorf("Lock should be failed, but now it succeeds.")
|
||||
}
|
||||
}
|
||||
|
||||
func lockerTest(lockerObj *Locker, succeedCount *int, count int, ch chan bool) {
|
||||
if success, _, _ := lockerObj.Lock(10000); !success {
|
||||
fmt.Printf("[%v]获取锁超时\n", time.Now())
|
||||
return
|
||||
}
|
||||
defer lockerObj.Unlock()
|
||||
|
||||
for i := 0; i < count; i++ {
|
||||
*succeedCount += 1
|
||||
}
|
||||
|
||||
ch <- true
|
||||
}
|
||||
Reference in New Issue
Block a user