<commit_before>package system

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
	"os"
	"strings"
	"time"

	sql "github.com/otoolep/rqlite/db"
	httpd "github.com/otoolep/rqlite/http"
	"github.com/otoolep/rqlite/store"
)

type Node struct {
	Addr    string
	Dir     string
	Store   *store.Store
	Service *httpd.Service
}

func (n *Node) Deprovision() {
	n.Store.Close()
	n.Service.Close()
	os.RemoveAll(n.Dir)
}

func (n *Node) WaitForLeader() error {
	_, err := n.Store.WaitForLeader(10 * time.Second)
	return err
}

func (n *Node) Execute(stmt string) (string, error) {
	j, err := json.Marshal([]string{stmt})
	if err != nil {
		return "", err
	}
	stmt = string(j)

	resp, err := http.Post("http://"+n.Addr+"/db/execute", "application/json", strings.NewReader(stmt))
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return "", err
	}
	return string(body), nil
}

func (n *Node) Query(stmt string) (string, error) {
	v, _ := url.Parse("http://" + n.Addr + "/db/query")
	v.RawQuery = url.Values{"q": []string{stmt}}.Encode()

	resp, err := http.Get(v.String())
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return "", err<commit_msg>GoDoc updates<commit_after>package system

import (
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"net/url"
	"os"
	"strings"
	"time"

	sql "github.com/otoolep/rqlite/db"
	httpd "github.com/otoolep/rqlite/http"
	"github.com/otoolep/rqlite/store"
)

// Node represents a node under test.
type Node struct {
	Addr    string
	Dir     string
	Store   *store.Store
	Service *httpd.Service
}

// Deprovisions removes all resources associated with the node.
func (n *Node) Deprovision() {
	n.Store.Close()
	n.Service.Close()
	os.RemoveAll(n.Dir)
}

// WaitForLeader blocks for up to 10 seconds until the node detects a leader.
func (n *Node) WaitForLeader() error {
	_, err := n.Store.WaitForLeader(10 * time.Second)
	return err
}

// Execute executes a single statement against the node.
func (n *Node) Execute(stmt string) (string, error) {
	j, err := json.Marshal([]string{stmt})
	if err != nil {
		return "", err
	}
	stmt = string(j)

	resp, err := http.Post("http://"+n.Addr+"/db/execute", "application/json", strings.NewReader(stmt))
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return "", err
	}
	return string(body), nil
}

// Query runs a single query against the node.
func (n *Node) Query(stmt string) (string, error) {
	v, _ := url.Parse("http://" + n.Addr + "/db/query")
	v.RawQuery = url.Values{"q": []string{stmt}}.Encode()

	resp, err := http.Get(v.String())
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return "", err
{'fraction_non_alphanumeric': 0.17395833333333333, 'fraction_numerical': 0.0020833333333333333, 'mean_word_length': 3.5802861685214626, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3182576', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1112, 'n_words': 275}