forked from apache/accumulo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a SteadyTime type in the Manager
This replaces Manager.getSteadyTime() long value with a concrete type to make it more apparent what time is being used. The serialization and deserialization logic have been encapsulated as methods to make the conversion consistent. This closes apache#4482
- Loading branch information
Showing
4 changed files
with
143 additions
and
12 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
62 changes: 62 additions & 0 deletions
62
server/manager/src/test/java/org/apache/accumulo/manager/ManagerTimeTest.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,62 @@ | ||
/* | ||
* 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 | ||
* | ||
* https://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 org.apache.accumulo.manager; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertArrayEquals; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.apache.accumulo.manager.ManagerTime.SteadyTime; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ManagerTimeTest { | ||
|
||
@Test | ||
public void testSteadyTime() { | ||
long time = System.nanoTime(); | ||
var steadyTime = SteadyTime.from(time); | ||
assertEquals(time, steadyTime.getTimeNs()); | ||
assertEquals(TimeUnit.NANOSECONDS.toMillis(time), steadyTime.getTimeMillis()); | ||
|
||
// make sure calling serialize on instance matches static helper | ||
byte[] serialized = steadyTime.serialize(); | ||
assertArrayEquals(serialized, SteadyTime.serialize(steadyTime)); | ||
|
||
// Verify deserialization matches original object | ||
var deserialized = SteadyTime.deserialize(serialized); | ||
assertEquals(steadyTime, deserialized); | ||
assertEquals(0, steadyTime.compareTo(deserialized)); | ||
} | ||
|
||
@Test | ||
public void testSteadyTimeSkew() { | ||
var time = System.nanoTime(); | ||
long skewAmount = 200000; | ||
var skewed = ManagerTime.fromSkew(skewAmount); | ||
assertTrue(skewed.getTimeNs() > time + skewAmount); | ||
assertTrue(skewed.compareTo(SteadyTime.from(time + skewAmount)) > 0); | ||
|
||
var steadyTime = SteadyTime.from(System.nanoTime()); | ||
var newSkew = ManagerTime.updatedSkew(steadyTime.serialize()); | ||
assertTrue(skewed.getTimeNs() > newSkew); | ||
assertTrue(skewed.compareTo(SteadyTime.from(newSkew)) > 0); | ||
} | ||
} |