INT-1188, Added support for MAC address discovery to ensure Global uniqueness of UUID

This commit is contained in:
Oleg Zhurakousky
2010-06-18 16:30:10 +00:00
parent 75d2add40c
commit 6c320719e1
3 changed files with 91 additions and 3 deletions

View File

@@ -0,0 +1,50 @@
/*
* Copyright 2002-2010 the original author or authors.
*
* Licensed 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 org.springframework.integration.core;
import java.util.UUID;
import org.junit.Assert;
import org.junit.Test;
/**
* @author Oleg Zhurakousky
*
*/
public class TimeBasedUUIDGeneratorTests {
@Test
public void testGreaterThen(){
UUID id = TimeBasedUUIDGenerator.generateId();
for (int i = 0; i < 1000; i++) {
UUID newId = TimeBasedUUIDGenerator.generateId();
// tests, that newly created UUID is always greater then the previous one.
Assert.assertTrue(newId.compareTo(id) == 1);
id = newId;
}
}
@Test
public void testUniqueness(){
long timestamp = System.currentTimeMillis();
UUID id = TimeBasedUUIDGenerator.generateIdFromTimestamp(timestamp);
for (int i = 0; i < 1000; i++) {
UUID newId = TimeBasedUUIDGenerator.generateIdFromTimestamp(timestamp);
// tests, that newly created UUID is always greater then the previous one.
Assert.assertTrue(newId.compareTo(id) == 1);
id = newId;
}
}
}