Navigation Menu

Skip to content

Commit

Permalink
index-recreate: add --url option
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Oct 25, 2017
1 parent 290054f commit 2d13837
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 10 deletions.
29 changes: 19 additions & 10 deletions lib/groonga/client/command-line/groonga-client-index-recreate.rb
Expand Up @@ -24,6 +24,7 @@ class Client
module CommandLine
class GroongaClientIndexRecreate
def initialize
@url = nil
@protocol = :http
@host = "localhost"
@port = nil
Expand All @@ -36,16 +37,17 @@ def initialize
def run(argv)
target_indexes = parse_command_line(argv)

@client = Client.new(:protocol => @protocol,
:host => @host,
:port => @port,
:read_timeout => @read_timeout,
:backend => :synchronous)

runner = Runner.new(@client, target_indexes)
runner.run do
@n_workers.times do
@client.database_unmap
Client.open(:url => @url,
:protocol => @protocol,
:host => @host,
:port => @port,
:read_timeout => @read_timeout,
:backend => :synchronous) do |client|
runner = Runner.new(client, target_indexes)
runner.run do
@n_workers.times do
client.database_unmap
end
end
end
end
Expand All @@ -60,6 +62,13 @@ def parse_command_line(argv)

parser.separator("Connection:")

parser.on("--url=URL",
"URL to connect to Groonga server.",
"If this option is specified,",
"--protocol, --host and --port are ignored.") do |url|
@url = url
end

available_protocols = [:http, :gqtp]
parser.on("--protocol=PROTOCOL", [:http, :gqtp],
"Protocol to connect to Groonga server.",
Expand Down
50 changes: 50 additions & 0 deletions test/command-line/test-index-recreate.rb
@@ -0,0 +1,50 @@
# Copyright (C) 2017 Kouhei Sutou <kou@clear-code.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

require "groonga/command/parser"

require "groonga/client"
require "groonga/client/test-helper"
require "groonga/client/command-line/groonga-client-index-recreate"

class TestCommandLineIndexRecreate < Test::Unit::TestCase
include Groonga::Client::TestHelper

def groonga_url
@groonga_server_runner.url.to_s
end

def dump
Groonga::Client.open(:url => groonga_url) do |client|
client.dump.body
end
end

def index_recreate(*arguments)
command_line = Groonga::Client::CommandLine::GroongaClientIndexRecreate.new
command_line.run(["--url", groonga_url, *arguments])
end

def test_no_alias
index_recreate
assert_equal(<<-DUMP.chomp, dump)
config_set alias.column Aliases.real_name
table_create Aliases TABLE_HASH_KEY ShortText
column_create Aliases real_name COLUMN_SCALAR ShortText
DUMP
end
end

0 comments on commit 2d13837

Please sign in to comment.