<commit_before>package test

import (
	"net/url"
	"sync"
	"time"

	"github.com/influxdb/influxdb"
	"github.com/influxdb/influxdb/messaging"
)

func init() {
	// Ensure the broker matches the handler's interface.
	_ = messaging.Handler{Broker: messaging.NewBroker()}
}

// MessagingClient represents a test client for the messaging broker.
type MessagingClient struct {
	mu      sync.Mutex
	index   uint64           // highest index
	conns   []*MessagingConn // list of all connections
	dataURL url.URL          // clients data node URL

	messagesByTopicID map[uint64][]*messaging.Message // message by topic

	PublishFunc func(*messaging.Message) (uint64, error)
	ConnFunc    func(topicID uint64) influxdb.MessagingConn
}

// NewMessagingClient returns a new instance of MessagingClient.
func NewMessagingClient(dataURL url.URL) *MessagingClient {
	c := &MessagingClient{
		messagesByTopicID: make(map[uint64][]*messaging.Message),
		dataURL:           dataURL,
	}
	c.PublishFunc = c.DefaultPublishFunc
	c.ConnFunc = c.DefaultConnFunc
	return c
}

// NewMessagingClient returns a new instance of MessagingClient.
func NewDefaultMessagingClient() *MessagingClient {
	testDataURL, _ := url.Parse("http://localhost:1234/data")
	return NewMessagingClient(*testDataURL)
}

func (c *MessagingClient) Open(path string) error { return nil }

// Close closes all open connections.
func (c *MessagingClient) Close() error {
	c.mu.Lock()
	defer c.mu.Unlock()

	for _, conn := range c.conns {
		conn.Close()
	}<commit_msg>Clear connections after closing them<commit_after>package test

import (
	"net/url"
	"sync"
	"time"

	"github.com/influxdb/influxdb"
	"github.com/influxdb/influxdb/messaging"
)

func init() {
	// Ensure the broker matches the handler's interface.
	_ = messaging.Handler{Broker: messaging.NewBroker()}
}

// MessagingClient represents a test client for the messaging broker.
type MessagingClient struct {
	mu      sync.Mutex
	index   uint64           // highest index
	conns   []*MessagingConn // list of all connections
	dataURL url.URL          // clients data node URL

	messagesByTopicID map[uint64][]*messaging.Message // message by topic

	PublishFunc func(*messaging.Message) (uint64, error)
	ConnFunc    func(topicID uint64) influxdb.MessagingConn
}

// NewMessagingClient returns a new instance of MessagingClient.
func NewMessagingClient(dataURL url.URL) *MessagingClient {
	c := &MessagingClient{
		messagesByTopicID: make(map[uint64][]*messaging.Message),
		dataURL:           dataURL,
	}
	c.PublishFunc = c.DefaultPublishFunc
	c.ConnFunc = c.DefaultConnFunc
	return c
}

// NewMessagingClient returns a new instance of MessagingClient.
func NewDefaultMessagingClient() *MessagingClient {
	testDataURL, _ := url.Parse("http://localhost:1234/data")
	return NewMessagingClient(*testDataURL)
}

func (c *MessagingClient) Open(path string) error { return nil }

// Close closes all open connections.
func (c *MessagingClient) Close() error {
	c.mu.Lock()
	defer c.mu.Unlock()

	for _, conn := range c.conns {
		conn.Close()
	}
	c.conns = nil
{'fraction_non_alphanumeric': 0.1066056245912361, 'fraction_numerical': 0.009156311314584695, 'mean_word_length': 4.098333333333334, 'pattern_counts': {'":': 0, '<': 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': '6566867', 'n_tokens_mistral': 1047, 'n_tokens_neox': 977, 'n_words': 256}