Skip to content

Commit

Permalink
development check-in
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Jan 31, 2012
1 parent 249c66a commit 2f560cc
Show file tree
Hide file tree
Showing 7 changed files with 442 additions and 53 deletions.
9 changes: 5 additions & 4 deletions symmetric/symmetric-assemble/TODO.txt
Expand Up @@ -36,10 +36,10 @@ DONE = +
+ make sure memory buffer is cleared when state goes to done

* Make SymmetricDS case sensitive
* Get rid of delimited identifier "force" properties
* Add property to platform that identifies the default case used by the database
* Pre-process SQL to make sure symmetric tables are quoted and use the default case of the database
* Pre-process symmetric tables to default them to the case of the database
+ Get rid of delimited identifier "force" properties
+ Add property to platform that identifies the default case used by the database
+ Pre-process SQL to make sure symmetric tables are quoted and use the default case of the database
+ Pre-process symmetric tables to default them to the case of the database

* Hook up JMX

Expand Down Expand Up @@ -93,4 +93,5 @@ Documentation
* Added stage management job (that purges staged files)
* Removed support for db.force.delimited.identifier.mode.on & db.force.delimited.identifier.mode.off
* Removed support for db.metadata.ignore.case
* SymmetricDS tables are now created in the default case of the database

Expand Up @@ -70,7 +70,6 @@
import org.jumpmind.symmetric.transport.IConcurrentConnectionManager;
import org.jumpmind.symmetric.transport.ITransportManager;
import org.jumpmind.symmetric.transport.TransportManagerFactory;
import org.jumpmind.symmetric.util.AppUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
Expand Down Expand Up @@ -283,7 +282,6 @@ public String getEngineName() {
}

public void setup() {
AppUtils.cleanupTempFiles();
getParameterService().rereadParameters();
if (!setup) {
setupDatabase(false);
Expand Down
Expand Up @@ -20,20 +20,17 @@
*/
package org.jumpmind.symmetric.util;

import java.io.File;
import java.io.IOException;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.TimeZone;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.FastDateFormat;
import org.slf4j.Logger;
Expand All @@ -47,14 +44,10 @@
*/
public class AppUtils {

private static boolean alreadyCleaned = false;

private static String UNKNOWN = "unknown";

private static Logger log = LoggerFactory.getLogger(AppUtils.class);

private static final String SYM_TEMP_SUFFIX = "sym.tmp";

private static String serverId;

private static FastDateFormat timezoneFormatter = FastDateFormat.getInstance("Z");
Expand Down Expand Up @@ -125,42 +118,6 @@ public static String getTimezoneOffset() {
return null;
}

/**
* Use this method to create any needed temporary files for SymmetricDS.
*/
public static File createTempFile(String token) throws IOException {
return File.createTempFile(token + ".", "." + SYM_TEMP_SUFFIX);
}

/**
* Clean up files created by {@link #createTempFile(String)}. This only be
* called while the engine is not synchronizing!
*/
public synchronized static void cleanupTempFiles() {
if (!alreadyCleaned) {
alreadyCleaned = true;
try {
File tmp = File.createTempFile("temp.", "." + SYM_TEMP_SUFFIX);
Iterator<File> it = FileUtils.iterateFiles(tmp.getParentFile(),
new String[] { SYM_TEMP_SUFFIX }, true);
int deletedCount = 0;
while (it.hasNext()) {
try {
FileUtils.forceDelete(it.next());
deletedCount++;
} catch (Exception ex) {
log.error("{}", ex.getMessage());
}
}
if (deletedCount > 1) {
log.warn("Cleaned {} stranded temporary files.", deletedCount);
}
} catch (Exception ex) {
log.error(ex.getMessage(),ex);
}
}
}

/**
* @param timezoneOffset
* see description for {@link #getTimezoneOffset()}
Expand Down
@@ -0,0 +1,113 @@
/*
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU Lesser General Public License (the
* "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* 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.jumpmind.symmetric.model;

import java.sql.Time;
import java.util.Calendar;

import org.junit.Assert;
import org.junit.Test;

public class NodeGroupChannelWindowTest {

@Test
public void testInWindowEnabled() {
NodeGroupChannelWindow window = new NodeGroupChannelWindow();
window.setEnabled(true);
window.setStartTime(Time.valueOf("13:00:00"));
window.setEndTime(Time.valueOf("14:00:00"));
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 13);
cal.set(Calendar.MINUTE, 5);
Assert.assertTrue(window.inTimeWindow(cal.getTime()));
cal.add(Calendar.DATE, 1);
Assert.assertTrue(window.inTimeWindow(cal.getTime()));
cal.add(Calendar.DATE, -100);
Assert.assertTrue(window.inTimeWindow(cal.getTime()));
}

@Test
public void testInWindowEnabledCrossDayBoundary() {
NodeGroupChannelWindow window = new NodeGroupChannelWindow();
window.setEnabled(true);
window.setStartTime(Time.valueOf("21:00:00"));
window.setEndTime(Time.valueOf("03:00:00"));
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 13);
cal.set(Calendar.MINUTE, 5);
Assert.assertFalse(window.inTimeWindow(cal.getTime()));
cal.set(Calendar.HOUR_OF_DAY, 22);
Assert.assertTrue(window.inTimeWindow(cal.getTime()));
cal.set(Calendar.HOUR_OF_DAY, 2);
Assert.assertTrue(window.inTimeWindow(cal.getTime()));
}

@Test
public void testInWindowDisabled() {
NodeGroupChannelWindow window = new NodeGroupChannelWindow();
window.setEnabled(false);
window.setStartTime(Time.valueOf("13:00:00"));
window.setEndTime(Time.valueOf("14:00:00"));
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 13);
cal.set(Calendar.MINUTE, 5);
Assert.assertTrue(window.inTimeWindow(cal.getTime()));
cal.add(Calendar.DATE, 1);
Assert.assertTrue(window.inTimeWindow(cal.getTime()));
cal.add(Calendar.DATE, -100);
Assert.assertTrue(window.inTimeWindow(cal.getTime()));
}

@Test
public void testOutOfWindowDisabled() {
NodeGroupChannelWindow window = new NodeGroupChannelWindow();
window.setEnabled(false);
window.setStartTime(Time.valueOf("13:00:00"));
window.setEndTime(Time.valueOf("14:00:00"));
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 17);
cal.set(Calendar.MINUTE, 5);
Assert.assertTrue(window.inTimeWindow(cal.getTime()));
cal.add(Calendar.DATE, 1);
Assert.assertTrue(window.inTimeWindow(cal.getTime()));
cal.add(Calendar.DATE, -100);
Assert.assertTrue(window.inTimeWindow(cal.getTime()));
}

@Test
public void testOutOfWindowEnabled() {
NodeGroupChannelWindow window = new NodeGroupChannelWindow();
window.setEnabled(true);
window.setStartTime(Time.valueOf("09:00:00"));
window.setEndTime(Time.valueOf("09:30:00"));
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 8);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 30);
Assert.assertFalse(window.inTimeWindow(cal.getTime()));
cal.add(Calendar.DATE, 423);
Assert.assertFalse(window.inTimeWindow(cal.getTime()));
cal.add(Calendar.DATE, -1);
Assert.assertFalse(window.inTimeWindow(cal.getTime()));
}



}
Expand Down
@@ -0,0 +1,46 @@
/*
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU Lesser General Public License (the
* "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* 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.jumpmind.symmetric.model;

import junit.framework.Assert;

import org.junit.Test;

public class NodeTest {

@Test
public void testIsVersionGreaterThan() {
Node test = new Node();
test.setSymmetricVersion("1.5.0");
Assert.assertTrue(test.isVersionGreaterThanOrEqualTo(1,3,0));
Assert.assertFalse(test.isVersionGreaterThanOrEqualTo(2,0,0));
Assert.assertFalse(test.isVersionGreaterThanOrEqualTo(2,0,0));
Assert.assertTrue(test.isVersionGreaterThanOrEqualTo(1,4,9,1));
Assert.assertTrue(test.isVersionGreaterThanOrEqualTo(1,5,0));
Assert.assertFalse(test.isVersionGreaterThanOrEqualTo(1,5,1));
test.setSymmetricVersion("1.5.0-SNAPSHOT");
Assert.assertTrue(test.isVersionGreaterThanOrEqualTo(1,3,0));
Assert.assertFalse(test.isVersionGreaterThanOrEqualTo(2,0,0));
Assert.assertTrue(test.isVersionGreaterThanOrEqualTo(1,5,0));
test.setSymmetricVersion("development");
Assert.assertTrue(test.isVersionGreaterThanOrEqualTo(1,3,0));
Assert.assertTrue(test.isVersionGreaterThanOrEqualTo(2,0,0));
}
}
Expand Down

0 comments on commit 2f560cc

Please sign in to comment.