-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detecting when a deserialized Map is immutable before changing it in …
…IndexDiskUsageStats (#77219) (#77390) This commit prevents errors that can happen if an empty fields map is serialized and deserialized in IndexDiskUsageStats.
- Loading branch information
Showing
2 changed files
with
38 additions
and
1 deletion.
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
37 changes: 37 additions & 0 deletions
37
.../test/java/org/elasticsearch/action/admin/indices/diskusage/IndexDiskUsageStatsTests.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,37 @@ | ||
/* | ||
* 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 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 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.indices.diskusage; | ||
|
||
import org.elasticsearch.common.io.stream.BytesStreamOutput; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import java.io.IOException; | ||
|
||
public class IndexDiskUsageStatsTests extends ESTestCase { | ||
|
||
public void testEmptySerialization() throws IOException { | ||
IndexDiskUsageStats emptyDndexDiskUsageStats = createEmptyDiskUsageStats(); | ||
try (BytesStreamOutput out = new BytesStreamOutput()) { | ||
emptyDndexDiskUsageStats.writeTo(out); | ||
try (StreamInput in = out.bytes().streamInput()) { | ||
IndexDiskUsageStats deserializedNodeStats = new IndexDiskUsageStats(in); | ||
assertEquals(emptyDndexDiskUsageStats.getIndexSizeInBytes(), deserializedNodeStats.getIndexSizeInBytes()); | ||
assertEquals(emptyDndexDiskUsageStats.getFields(), deserializedNodeStats.getFields()); | ||
// Now just making sure that an exception doesn't get thrown here: | ||
deserializedNodeStats.addStoredField(randomAlphaOfLength(10), randomNonNegativeLong()); | ||
} | ||
} | ||
} | ||
|
||
private IndexDiskUsageStats createEmptyDiskUsageStats() { | ||
return new IndexDiskUsageStats(randomNonNegativeLong()); | ||
} | ||
|
||
} |