本文整理匯總了Golang中github.com/rafaeljusto/shelter/dao.DomainDAO.RemoveAll方法的典型用法代碼示例。如果您正苦於以下問題:Golang DomainDAO.RemoveAll方法的具體用法?Golang DomainDAO.RemoveAll怎麽用?Golang DomainDAO.RemoveAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/rafaeljusto/shelter/dao.DomainDAO
的用法示例。
在下文中一共展示了DomainDAO.RemoveAll方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: scanReport
// Generates a report with the amount of time of a scan
func scanReport(domainDAO dao.DomainDAO, scanDAO dao.ScanDAO, scanConfig ScanTestConfigFile) {
report := " # | Total | DPS | Memory (MB)\n" +
"-----------------------------------------------------\n"
// Report variables
scale := []int{10, 50, 100, 500, 1000, 5000,
10000, 50000, 100000, 500000, 1000000, 5000000}
dnskey, privateKey, err := utils.GenerateKey()
if err != nil {
utils.Fatalln("Error generating DNSKEY", err)
}
reportHandler := ReportHandler{
DNSKEY: dnskey,
PrivateKey: privateKey,
}
server.Handler = reportHandler
dns.DefaultServeMux = nil
for _, numberOfItems := range scale {
utils.Println(fmt.Sprintf("Generating report - scale %d", numberOfItems))
for i := 0; i < numberOfItems; i++ {
if i%1000 == 0 {
utils.PrintProgress("building scenario", (i*100)/numberOfItems)
}
fqdn := fmt.Sprintf("domain%d.br.", i)
generateAndSaveDomain(fqdn, domainDAO, dnskey)
}
utils.PrintProgress("building scenario", 100)
totalDuration, domainsPerSecond := calculateScanDurations(numberOfItems, scanDAO)
var memStats runtime.MemStats
runtime.ReadMemStats(&memStats)
report += fmt.Sprintf("% -8d | %16s | %4d | %14.2f\n",
numberOfItems,
time.Duration(int64(totalDuration)).String(),
domainsPerSecond,
float64(memStats.Alloc)/float64(MB),
)
if err := domainDAO.RemoveAll(); err != nil {
// When the result set is too big to remove, we got a timeout error from the
// connection, but it's ok
//utils.Fatalln("Error removing domains generated for report", err)
}
}
utils.WriteReport(scanConfig.Report.File, report)
}
示例2: main
func main() {
flag.Parse()
var config DomainDAOTestConfigFile
err := utils.ReadConfigFile(configFilePath, &config)
if err == utils.ErrConfigFileUndefined {
fmt.Println(err.Error())
fmt.Println("Usage:")
flag.PrintDefaults()
return
} else if err != nil {
utils.Fatalln("Error reading configuration file", err)
}
database, databaseSession, err := mongodb.Open(
[]string{config.Database.URI},
config.Database.Name,
false, "", "",
)
if err != nil {
utils.Fatalln("Error connecting the database", err)
}
defer databaseSession.Close()
domainDAO := dao.DomainDAO{
Database: database,
}
// If there was some problem in the last test, there could be some data in the
// database, so let's clear it to don't affect this test. We avoid checking the error,
// because if the collection does not exist yet, it will be created in the first
// insert
domainDAO.RemoveAll()
domainLifeCycle(domainDAO)
domainsLifeCycle(domainDAO)
domainUniqueFQDN(domainDAO)
domainConcurrency(domainDAO)
domainsPagination(domainDAO)
domainsNotification(domainDAO)
domainsExpand(domainDAO)
domainFilter(domainDAO)
// Domain DAO performance report is optional and only generated when the report file
// path parameter is given
if report {
domainDAOPerformanceReport(config.Report.ReportFile, domainDAO)
}
utils.Println("SUCCESS!")
}
示例3: ClearDatabase
// Function created to remove all entries from the database to ensure that the tests
// enviroments are always equal
func ClearDatabase(database *mgo.Database) {
domainDAO := dao.DomainDAO{
Database: database,
}
domainDAO.RemoveAll()
scanDAO := dao.ScanDAO{
Database: database,
}
scanDAO.RemoveAll()
}
示例4: main
func main() {
flag.Parse()
var restConfig RESTHandlerDomainVerificationTestConfigFile
err := utils.ReadConfigFile(configFilePath, &restConfig)
config.ShelterConfig = restConfig.Config
if err == utils.ErrConfigFileUndefined {
fmt.Println(err.Error())
fmt.Println("Usage:")
flag.PrintDefaults()
return
} else if err != nil {
utils.Fatalln("Error reading configuration file", err)
}
database, databaseSession, err := mongodb.Open(
restConfig.Database.URIs,
restConfig.Database.Name,
false, "", "",
)
if err != nil {
utils.Fatalln("Error connecting the database", err)
}
defer databaseSession.Close()
domainDAO := dao.DomainDAO{
Database: database,
}
// If there was some problem in the last test, there could be some data in the
// database, so let's clear it to don't affect this test. We avoid checking the error,
// because if the collection does not exist yet, it will be created in the first
// insert
domainDAO.RemoveAll()
utils.StartDNSServer(restConfig.DNSServerPort, restConfig.Scan.UDPMaxSize)
scanDomain()
scanPersistedDomain(domainDAO)
queryDomain()
utils.Println("SUCCESS!")
}
示例5: domainsLifeCycle
//.........這裏部分代碼省略.........
} else if !utils.CompareDomain(*domain, domainRetrieved) {
utils.Fatalln(fmt.Sprintf("Domain %s updated in being persisted wrongly", domain.FQDN), nil)
}
}
// Check if find all really return all domains
allDomainsChannel, err := domainDAO.FindAllAsync()
if err != nil {
utils.Fatalln("Error while retrieving all domains from database", err)
}
var allDomains []model.Domain
for {
domainRetrieved := <-allDomainsChannel
if domainRetrieved.Error != nil {
utils.Fatalln("Error while retrieving all domains from database", err)
} else if domainRetrieved.Domain == nil {
break
}
allDomains = append(allDomains, *domainRetrieved.Domain)
}
if len(allDomains) != len(domains) {
utils.Fatalln(fmt.Sprintf("FindAll method is not returning all domains we expected %d but got %d",
len(domains), len(allDomains)), nil)
}
// Detected a problem in FindAsync method on 2014-01-17 where we were returning the same
// object many times because we were reusing the same pointer. For that reason we are
// going to add a test to check if the items returned are the same set of the inserted
// ones
for _, domain := range domains {
found := false
for _, domainRetrieved := range allDomains {
if domainRetrieved.Id.Hex() == domain.Id.Hex() {
found = true
break
}
}
if !found {
utils.Fatalln("FindAll method is not returning all objects "+
"that were inserted, apparently there are duplicated objects in the result set", nil)
}
}
// Remove domains
domainResults = domainDAO.RemoveMany(domains)
for _, domainResult := range domainResults {
if domainResult.Error != nil {
utils.Fatalln(fmt.Sprintf("Error while trying to remove domain %s from database",
domainResult.Domain.FQDN), domainResult.Error)
}
}
for _, domain := range domains {
// Check removals
if _, err := domainDAO.FindByFQDN(domain.FQDN); err == nil {
utils.Fatalln(fmt.Sprintf("Domain %s was not removed from database", domain.FQDN), nil)
}
}
// Let's add and remove the domains again to test the remove all method
domainResults = domainDAO.SaveMany(domains)
for _, domainResult := range domainResults {
if domainResult.Error != nil {
utils.Fatalln(fmt.Sprintf("Couldn't save domain %s in database",
domainResult.Domain.FQDN), domainResult.Error)
}
}
if err := domainDAO.RemoveAll(); err != nil {
utils.Fatalln("Couldn't remove all domains", err)
}
allDomainsChannel, err = domainDAO.FindAllAsync()
if err != nil {
utils.Fatalln("Error while retrieving all domains from database", err)
}
allDomains = []model.Domain{}
for {
domainRetrieved := <-allDomainsChannel
if domainRetrieved.Error != nil {
utils.Fatalln("Error while retrieving all domains from database", err)
} else if domainRetrieved.Domain == nil {
break
}
allDomains = append(allDomains, *domainRetrieved.Domain)
}
if len(allDomains) > 0 {
utils.Fatalln("RemoveAll method is not removing the domains from the database", nil)
}
}