public void testBug42750() throws Exception { Properties props = new Properties(); Connection conn = TestUtil.getConnection(props); char fileSeparator = System.getProperty("file.separator").charAt(0); Misc.getGemFireCache(); conn.createStatement(); String path = "." + fileSeparator + "test_dir"; File file = new File(path); if (!file.mkdirs() && !file.isDirectory()) { throw new DiskAccessException( "Could not create directory for " + " default disk store : " + file.getAbsolutePath(), (Region) null); } try { Connection conn1; conn1 = TestUtil.getConnection(); Statement stmt1 = conn1.createStatement(); stmt1.execute("Create DiskStore " + "TestPersistenceDiskStore" + "'" + path + "'"); conn1.close(); TestUtil.shutDown(); conn1 = TestUtil.getConnection(); stmt1 = conn1.createStatement(); stmt1.execute("Create DiskStore " + "TestPersistenceDiskStore" + "'" + path + "'"); fail("Disk store creation should fail as the disk store already exists"); } catch (SQLException e) { assertEquals(e.getSQLState(), "X0Y68"); } }
public void testDiskStoreConfig2() throws SQLException { Connection conn = getConnection(); Statement s = conn.createStatement(); File f1 = new File("dir1"); f1.mkdir(); File f2 = new File("dir2"); f2.mkdir(); s.execute("create DiskStore testDiskStore3 ('dir1', 'dir2') WriteBufferSize 7878"); DiskStore ds = Misc.getGemFireCache().findDiskStore("TESTDISKSTORE3"); assertEquals(ds.getAllowForceCompaction(), DiskStoreFactory.DEFAULT_ALLOW_FORCE_COMPACTION); assertEquals(ds.getAutoCompact(), DiskStoreFactory.DEFAULT_AUTO_COMPACT); assertEquals(ds.getCompactionThreshold(), DiskStoreFactory.DEFAULT_COMPACTION_THRESHOLD); assertEquals(ds.getMaxOplogSize(), DiskStoreFactory.DEFAULT_MAX_OPLOG_SIZE); assertEquals(ds.getQueueSize(), DiskStoreFactory.DEFAULT_QUEUE_SIZE); assertEquals(ds.getTimeInterval(), DiskStoreFactory.DEFAULT_TIME_INTERVAL); assertEquals(ds.getWriteBufferSize(), 7878); assertEquals(ds.getDiskDirs().length, 2); Set<String> files = new HashSet<String>(); files.add(new File(".", "dir1").getAbsolutePath()); files.add(new File(".", "dir2").getAbsolutePath()); assertEquals(ds.getDiskDirs().length, 2); for (File file : ds.getDiskDirs()) { assertTrue(files.remove(file.getAbsolutePath())); } assertTrue(files.isEmpty()); assertNotNull(ds); s = conn.createStatement(); s.execute("drop DiskStore testDiskStore3"); // cleanUpDirs(new File[] { f1, f2 }); }
// [sjigyasu] In AbstractEventImpl, we only need to return the strings for // AFTER_INSERT, AFTER_UPDATE and AFTER_DELETE because the // listeners are going to set only these types. AbstractEventImpl does // not hold the bulk dml string anyway. @Override public String getDMLString() { ResultSetMetaData metadata, pkMetaData; // Return empty string String dmlString = ""; ResultSet rows, pkResultSet; final String tableName = this.getTableName(); try { switch (this.getType()) { case AFTER_INSERT: case BEFORE_INSERT: metadata = getResultSetMetaData(); dmlString = AsyncEventHelper.getInsertString(tableName, (TableMetaData) metadata, false); break; case AFTER_UPDATE: case BEFORE_UPDATE: rows = getNewRowsAsResultSet(); metadata = rows.getMetaData(); pkResultSet = getPrimaryKeysAsResultSet(); pkMetaData = pkResultSet.getMetaData(); dmlString = AsyncEventHelper.getUpdateString(tableName, pkMetaData, metadata); break; case AFTER_DELETE: case BEFORE_DELETE: pkResultSet = getPrimaryKeysAsResultSet(); pkMetaData = pkResultSet.getMetaData(); dmlString = AsyncEventHelper.getDeleteString(tableName, pkMetaData); break; case BULK_DML: // This should never happen dmlString = this.toString(); break; case BULK_INSERT: // This should never happen dmlString = this.toString(); break; default: // should never happen dmlString = this.toString(); } } catch (SQLException e) { if (Misc.getCacheLogWriter().infoEnabled()) { Misc.getCacheLogWriter().info("AbstractEventImpl##getDMLString::" + e.getMessage()); } } return dmlString; }
private void dataPersistenceOfPR(String partitionClause) throws Exception { Properties props = new Properties(); Connection conn = TestUtil.getConnection(props); char fileSeparator = System.getProperty("file.separator").charAt(0); GemFireCacheImpl cache = Misc.getGemFireCache(); Statement stmt = conn.createStatement(); if (cache.findDiskStore("TestPersistenceDiskStore") == null) { String path = "." + fileSeparator + "test_dir"; File file = new File(path); if (!file.mkdirs() && !file.isDirectory()) { throw new DiskAccessException( "Could not create directory for " + " default disk store : " + file.getAbsolutePath(), (Region) null); } try { Connection conn1; conn1 = TestUtil.getConnection(); Statement stmt1 = conn1.createStatement(); stmt1.execute("Create DiskStore " + "TestPersistenceDiskStore" + "'" + path + "'"); conn1.close(); } catch (SQLException e) { throw GemFireXDRuntimeException.newRuntimeException(null, e); } } stmt.execute("create schema trade"); stmt.execute( "create table trade.customers (cid int not null, cust_name varchar(100), tid int, " + "primary key (cid)) " + partitionClause + " PERSISTENT " + "'" + "TestPersistenceDiskStore" + "'"); PreparedStatement ps = conn.prepareStatement("insert into trade.customers values (?,?,?)"); for (int i = 1; i < 31; ++i) { ps.setInt(1, i); ps.setString(2, "name" + i); ps.setInt(3, i); ps.executeUpdate(); } conn.close(); shutDown(); conn = TestUtil.getConnection(); stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from trade.customers"); int expected = 465; int actual = 0; while (rs.next()) { int val = rs.getInt(1); actual += val; } assertEquals(expected, actual); }
public void testDiskStoreConfig1() throws Exception { Connection conn = getConnection(); Statement s = conn.createStatement(); File f1 = new File("dir1"); f1.mkdir(); File f2 = new File("dir2"); f2.mkdir(); File f3 = new File("dir3"); f3.mkdir(); s.execute( "create DiskStore testDiskStore2 maxlogsize 448 autocompact false " + " allowforcecompaction true compactionthreshold 80 TimeInterval 23344 " + "Writebuffersize 192923 queuesize 1734 ('dir1' 456, 'dir2', 'dir3' 55556 )"); DiskStore ds = Misc.getGemFireCache().findDiskStore("TESTDISKSTORE2"); assertNotNull(ds); assertEquals(ds.getAllowForceCompaction(), true); assertEquals(ds.getAutoCompact(), false); assertEquals(ds.getCompactionThreshold(), 80); assertEquals(448, ds.getMaxOplogSize()); assertEquals(ds.getQueueSize(), 1734); assertEquals(ds.getTimeInterval(), 23344); assertEquals(ds.getWriteBufferSize(), 192923); assertEquals(ds.getDiskDirs().length, 3); Set<String> files = new HashSet<String>(); files.add(new File(".", "dir1").getAbsolutePath()); files.add(new File(".", "dir2").getAbsolutePath()); files.add(new File(".", "dir3").getAbsolutePath()); assertEquals(ds.getDiskDirs().length, 3); for (File file : ds.getDiskDirs()) { assertTrue(files.remove(file.getAbsolutePath())); } assertTrue(files.isEmpty()); List<Long> sizes = new ArrayList<Long>(); int i = 0; sizes.add(456l); sizes.add(0l); sizes.add(55556l); for (long size : ds.getDiskDirSizes()) { assertEquals(size, sizes.get(i++).longValue()); } // cleanUpDirs(new File[] { f1, f2, f3 }); s.execute("drop DiskStore testDiskStore2"); }
public void testDiskStoreWithDefaultConfig() throws SQLException { Connection conn = getConnection(); Statement s = conn.createStatement(); s.execute("create DiskStore testDiskStore1"); DiskStore ds = Misc.getGemFireCache().findDiskStore("TESTDISKSTORE1"); assertEquals(ds.getAllowForceCompaction(), DiskStoreFactory.DEFAULT_ALLOW_FORCE_COMPACTION); assertEquals(ds.getAutoCompact(), DiskStoreFactory.DEFAULT_AUTO_COMPACT); assertEquals(ds.getCompactionThreshold(), DiskStoreFactory.DEFAULT_COMPACTION_THRESHOLD); assertEquals(ds.getMaxOplogSize(), DiskStoreFactory.DEFAULT_MAX_OPLOG_SIZE); assertEquals(ds.getQueueSize(), DiskStoreFactory.DEFAULT_QUEUE_SIZE); assertEquals(ds.getTimeInterval(), DiskStoreFactory.DEFAULT_TIME_INTERVAL); assertEquals(ds.getWriteBufferSize(), DiskStoreFactory.DEFAULT_WRITE_BUFFER_SIZE); assertEquals(ds.getDiskDirs().length, 1); assertEquals(ds.getDiskDirs()[0].getAbsolutePath(), new File(".").getAbsolutePath()); assertNotNull(ds); s = conn.createStatement(); s.execute("drop DiskStore testDiskStore1"); }
@Override public AbstractRegion getRegion() { return this.tqi != null ? this.tqi.getRegion() : (this.td != null ? (AbstractRegion) Misc.getRegionByPath(this.td, null, false) : null); }