forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing GetDatabaseConfigurationAction response serialization (elastic…
…#119233) Co-authored-by: Joe Gallo <joe.gallo@elastic.co>
- Loading branch information
Showing
4 changed files
with
256 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 119233 | ||
summary: Fixing `GetDatabaseConfigurationAction` response serialization | ||
area: Ingest Node | ||
type: bug | ||
issues: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...rg/elasticsearch/ingest/geoip/direct/GetDatabaseConfigurationActionNodeResponseTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.ingest.geoip.direct; | ||
|
||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.cluster.node.DiscoveryNodeUtils; | ||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.test.AbstractWireSerializingTestCase; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static java.util.Collections.emptySet; | ||
|
||
public class GetDatabaseConfigurationActionNodeResponseTests extends AbstractWireSerializingTestCase< | ||
GetDatabaseConfigurationAction.NodeResponse> { | ||
@Override | ||
protected Writeable.Reader<GetDatabaseConfigurationAction.NodeResponse> instanceReader() { | ||
return GetDatabaseConfigurationAction.NodeResponse::new; | ||
} | ||
|
||
@Override | ||
protected GetDatabaseConfigurationAction.NodeResponse createTestInstance() { | ||
return getRandomDatabaseConfigurationActionNodeResponse(); | ||
} | ||
|
||
static GetDatabaseConfigurationAction.NodeResponse getRandomDatabaseConfigurationActionNodeResponse() { | ||
return new GetDatabaseConfigurationAction.NodeResponse(randomDiscoveryNode(), getRandomDatabaseConfigurationMetadata()); | ||
} | ||
|
||
private static DiscoveryNode randomDiscoveryNode() { | ||
return DiscoveryNodeUtils.builder(randomAlphaOfLength(6)).roles(emptySet()).build(); | ||
} | ||
|
||
static List<DatabaseConfigurationMetadata> getRandomDatabaseConfigurationMetadata() { | ||
return randomList( | ||
0, | ||
20, | ||
() -> new DatabaseConfigurationMetadata( | ||
new DatabaseConfiguration( | ||
randomAlphaOfLength(20), | ||
randomAlphaOfLength(20), | ||
randomFrom( | ||
List.of( | ||
new DatabaseConfiguration.Local(randomAlphaOfLength(10)), | ||
new DatabaseConfiguration.Web(), | ||
new DatabaseConfiguration.Ipinfo(), | ||
new DatabaseConfiguration.Maxmind(randomAlphaOfLength(10)) | ||
) | ||
) | ||
), | ||
randomNonNegativeLong(), | ||
randomNonNegativeLong() | ||
) | ||
); | ||
} | ||
|
||
@Override | ||
protected GetDatabaseConfigurationAction.NodeResponse mutateInstance(GetDatabaseConfigurationAction.NodeResponse instance) | ||
throws IOException { | ||
return null; | ||
} | ||
|
||
protected NamedWriteableRegistry getNamedWriteableRegistry() { | ||
return new NamedWriteableRegistry( | ||
List.of( | ||
new NamedWriteableRegistry.Entry( | ||
DatabaseConfiguration.Provider.class, | ||
DatabaseConfiguration.Maxmind.NAME, | ||
DatabaseConfiguration.Maxmind::new | ||
), | ||
new NamedWriteableRegistry.Entry( | ||
DatabaseConfiguration.Provider.class, | ||
DatabaseConfiguration.Ipinfo.NAME, | ||
DatabaseConfiguration.Ipinfo::new | ||
), | ||
new NamedWriteableRegistry.Entry( | ||
DatabaseConfiguration.Provider.class, | ||
DatabaseConfiguration.Local.NAME, | ||
DatabaseConfiguration.Local::new | ||
), | ||
new NamedWriteableRegistry.Entry( | ||
DatabaseConfiguration.Provider.class, | ||
DatabaseConfiguration.Web.NAME, | ||
DatabaseConfiguration.Web::new | ||
) | ||
) | ||
); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...va/org/elasticsearch/ingest/geoip/direct/GetDatabaseConfigurationActionResponseTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.ingest.geoip.direct; | ||
|
||
import org.elasticsearch.ElasticsearchException; | ||
import org.elasticsearch.action.FailedNodeException; | ||
import org.elasticsearch.cluster.ClusterName; | ||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
import org.elasticsearch.common.io.stream.Writeable; | ||
import org.elasticsearch.test.AbstractWireSerializingTestCase; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class GetDatabaseConfigurationActionResponseTests extends AbstractWireSerializingTestCase<GetDatabaseConfigurationAction.Response> { | ||
@Override | ||
protected Writeable.Reader<GetDatabaseConfigurationAction.Response> instanceReader() { | ||
return GetDatabaseConfigurationAction.Response::new; | ||
} | ||
|
||
@Override | ||
protected GetDatabaseConfigurationAction.Response createTestInstance() { | ||
return new GetDatabaseConfigurationAction.Response( | ||
GetDatabaseConfigurationActionNodeResponseTests.getRandomDatabaseConfigurationMetadata(), | ||
getTestClusterName(), | ||
getTestNodeResponses(), | ||
getTestFailedNodeExceptions() | ||
); | ||
} | ||
|
||
@Override | ||
protected GetDatabaseConfigurationAction.Response mutateInstance(GetDatabaseConfigurationAction.Response instance) throws IOException { | ||
return null; | ||
} | ||
|
||
private ClusterName getTestClusterName() { | ||
return new ClusterName(randomAlphaOfLength(30)); | ||
} | ||
|
||
private List<GetDatabaseConfigurationAction.NodeResponse> getTestNodeResponses() { | ||
return randomList(0, 20, GetDatabaseConfigurationActionNodeResponseTests::getRandomDatabaseConfigurationActionNodeResponse); | ||
} | ||
|
||
private List<FailedNodeException> getTestFailedNodeExceptions() { | ||
return randomList( | ||
0, | ||
5, | ||
() -> new FailedNodeException( | ||
randomAlphaOfLength(10), | ||
randomAlphaOfLength(20), | ||
new ElasticsearchException(randomAlphaOfLength(10)) | ||
) | ||
); | ||
} | ||
|
||
protected NamedWriteableRegistry getNamedWriteableRegistry() { | ||
return new NamedWriteableRegistry( | ||
List.of( | ||
new NamedWriteableRegistry.Entry( | ||
DatabaseConfiguration.Provider.class, | ||
DatabaseConfiguration.Maxmind.NAME, | ||
DatabaseConfiguration.Maxmind::new | ||
), | ||
new NamedWriteableRegistry.Entry( | ||
DatabaseConfiguration.Provider.class, | ||
DatabaseConfiguration.Ipinfo.NAME, | ||
DatabaseConfiguration.Ipinfo::new | ||
), | ||
new NamedWriteableRegistry.Entry( | ||
DatabaseConfiguration.Provider.class, | ||
DatabaseConfiguration.Local.NAME, | ||
DatabaseConfiguration.Local::new | ||
), | ||
new NamedWriteableRegistry.Entry( | ||
DatabaseConfiguration.Provider.class, | ||
DatabaseConfiguration.Web.NAME, | ||
DatabaseConfiguration.Web::new | ||
) | ||
) | ||
); | ||
} | ||
} |