@@ -138,4 +138,41 @@ public void testWarnIfPreRelease() {
138
138
139
139
}
140
140
141
+ public void testNodeAttributes () throws IOException {
142
+ String attr = randomAsciiOfLength (5 );
143
+ Settings .Builder settings = baseSettings ().put (Node .NODE_ATTRIBUTES .getKey () + "test_attr" , attr );
144
+ try (Node node = new MockNode (settings .build (), Collections .singleton (MockTcpTransportPlugin .class ))) {
145
+ final Settings nodeSettings = randomBoolean () ? node .settings () : node .getEnvironment ().settings ();
146
+ assertEquals (attr , Node .NODE_ATTRIBUTES .get (nodeSettings ).getAsMap ().get ("test_attr" ));
147
+ }
148
+
149
+ // leading whitespace not allowed
150
+ attr = " leading" ;
151
+ settings = baseSettings ().put (Node .NODE_ATTRIBUTES .getKey () + "test_attr" , attr );
152
+ try (Node node = new MockNode (settings .build (), Collections .singleton (MockTcpTransportPlugin .class ))) {
153
+ fail ("should not allow a node attribute with leading whitespace" );
154
+ } catch (IllegalArgumentException e ) {
155
+ assertEquals ("node.attr.test_attr cannot have leading or trailing whitespace [ leading]" , e .getMessage ());
156
+ }
157
+
158
+ // trailing whitespace not allowed
159
+ attr = "trailing " ;
160
+ settings = baseSettings ().put (Node .NODE_ATTRIBUTES .getKey () + "test_attr" , attr );
161
+ try (Node node = new MockNode (settings .build (), Collections .singleton (MockTcpTransportPlugin .class ))) {
162
+ fail ("should not allow a node attribute with trailing whitespace" );
163
+ } catch (IllegalArgumentException e ) {
164
+ assertEquals ("node.attr.test_attr cannot have leading or trailing whitespace [trailing ]" , e .getMessage ());
165
+ }
166
+ }
167
+
168
+ private static Settings .Builder baseSettings () {
169
+ final Path tempDir = createTempDir ();
170
+ return Settings .builder ()
171
+ .put (ClusterName .CLUSTER_NAME_SETTING .getKey (), InternalTestCluster .clusterName ("single-node-cluster" , randomLong ()))
172
+ .put (Environment .PATH_HOME_SETTING .getKey (), tempDir )
173
+ .put (NetworkModule .HTTP_ENABLED .getKey (), false )
174
+ .put ("transport.type" , "mock-socket-network" )
175
+ .put (Node .NODE_DATA_SETTING .getKey (), true );
176
+ }
177
+
141
178
}
0 commit comments