-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make various TDigest implementations Serializable (so that it can be …
…used with Spark).
- Loading branch information
1 parent
422561e
commit f4ed7af
Showing
8 changed files
with
81 additions
and
9 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
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
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
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
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
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
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
60 changes: 60 additions & 0 deletions
60
src/test/java/com/tdunning/math/stats/TDigestSerializationTest.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,60 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.tdunning.math.stats; | ||
|
||
import org.apache.commons.lang3.SerializationUtils; | ||
import org.junit.*; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
|
||
/** | ||
* Verifies that the various TDigest implementations can be serialized. | ||
* | ||
* Serializability is important, for example, if we want to use t-digests with Spark. | ||
*/ | ||
public class TDigestSerializationTest { | ||
|
||
@Test | ||
public void testTreeDigest() { | ||
assertSerializesAndDeserializes(new TreeDigest(100)); | ||
} | ||
|
||
@Test | ||
public void testMergingDigest() { | ||
assertSerializesAndDeserializes(new MergingDigest(100)); | ||
} | ||
|
||
@Test | ||
public void testAVLTreeDigest() { | ||
assertSerializesAndDeserializes(new AVLTreeDigest(100)); | ||
} | ||
|
||
@Test | ||
public void testArrayDigest() { | ||
assertSerializesAndDeserializes(new ArrayDigest(32, 100)); | ||
} | ||
|
||
protected void assertSerializesAndDeserializes(TDigest tdigest) { | ||
assertNotNull(SerializationUtils.deserialize(SerializationUtils.serialize(tdigest))); | ||
|
||
tdigest.add(1); | ||
assertNotNull(SerializationUtils.deserialize(SerializationUtils.serialize(tdigest))); | ||
} | ||
} |