Skip to content

Commit

Permalink
remove count of tables coz @@DBTS has not the same behavior in latest…
Browse files Browse the repository at this point in the history
… sql server version
  • Loading branch information
Mimetis committed Nov 30, 2022
1 parent 7536a94 commit 36f481f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ public async Task<ClientSyncChanges> GetEstimatedChangesCountAsync(ScopeInfoClie
// get rows inserted / updated elsewhere since the sync is not over
(context, clientTimestamp) = await this.InternalGetLocalTimestampAsync(context, runner.Connection, runner.Transaction, runner.CancellationToken, runner.Progress).ConfigureAwait(false);

var ts = await this.GetLocalTimestampAsync();
Console.WriteLine($"SYNC TS InternalGetChangesAsync InternalGetLocalTimestampAsync:{ts}");
Debug.WriteLine($"SYNC TS InternalGetChangesAsync InternalGetLocalTimestampAsync:{ts}");

// Create a batch info
string info = connection != null && !string.IsNullOrEmpty(connection.Database) ? $"{connection.Database}_LOCAL_GETCHANGES" : "LOCAL_GETCHANGES";
var clientBatchInfo = new BatchInfo(this.Options.BatchDirectory, info: info);
Expand All @@ -219,6 +223,10 @@ public async Task<ClientSyncChanges> GetEstimatedChangesCountAsync(ScopeInfoClie
clientChangesSelected = await this.InternalGetChangesAsync(cScopeInfo,
context, cScopeInfoClient.IsNewScope, cScopeInfoClient.LastSyncTimestamp, clientTimestamp, remoteScopeId, this.Provider.SupportsMultipleActiveResultSets, clientBatchInfo,
runner.Connection, runner.Transaction, runner.CancellationToken, runner.Progress).ConfigureAwait(false);

ts = await this.GetLocalTimestampAsync();
Console.WriteLine($"SYNC TS InternalGetChangesAsync InternalGetChangesAsync:{ts}");
Debug.WriteLine($"SYNC TS InternalGetChangesAsync InternalGetChangesAsync:{ts}");
}

var databaseChangesSelectedArgs = new DatabaseChangesSelectedArgs(context, cScopeInfoClient.LastSyncTimestamp, clientTimestamp,
Expand Down
28 changes: 28 additions & 0 deletions Projects/Dotmim.Sync.Core/SyncAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,26 @@ public async Task<SyncResult> SynchronizeAsync(string scopeName, SyncSetup setup
ScopeInfo cScopeInfo;
(context, cScopeInfo) = await this.LocalOrchestrator.InternalEnsureScopeInfoAsync(context, default, default, cancellationToken, progress).ConfigureAwait(false);

var ts = await this.LocalOrchestrator.GetLocalTimestampAsync();
Console.WriteLine($"SYNC TS:{ts}");
Debug.WriteLine($"SYNC TS:{ts}");

ScopeInfoClient cScopeInfoClient;
(context, cScopeInfoClient) = await this.LocalOrchestrator.InternalEnsureScopeInfoClientAsync(context, default, default, cancellationToken, progress).ConfigureAwait(false);

ts = await this.LocalOrchestrator.GetLocalTimestampAsync();
Console.WriteLine($"SYNC TS InternalEnsureScopeInfoClientAsync:{ts}");
Debug.WriteLine($"SYNC TS InternalEnsureScopeInfoClientAsync:{ts}");

// Check if we have a problem with the SyncSetup local and the one coming from server
// Let a chance to the user to update the local setup accordingly to the server one
isConflicting = false;
(context, isConflicting, cScopeInfo, sScopeInfo) = await this.LocalOrchestrator.InternalIsConflictingSetupAsync(context, setup, cScopeInfo, sScopeInfo).ConfigureAwait(false);

ts = await this.LocalOrchestrator.GetLocalTimestampAsync();
Console.WriteLine($"SYNC TS InternalIsConflictingSetupAsync:{ts}");
Debug.WriteLine($"SYNC TS InternalIsConflictingSetupAsync:{ts}");

if (isConflicting)
{
context.ProgressPercentage = 1;
Expand Down Expand Up @@ -370,6 +382,10 @@ public async Task<SyncResult> SynchronizeAsync(string scopeName, SyncSetup setup
(context, cScopeInfo) = await this.LocalOrchestrator.InternalProvisionClientAsync(sScopeInfo, cScopeInfo, context, provision, false, default, default, cancellationToken, progress).ConfigureAwait(false);
}

ts = await this.LocalOrchestrator.GetLocalTimestampAsync();
Console.WriteLine($"SYNC TS InternalProvisionClientAsync:{ts}");
Debug.WriteLine($"SYNC TS InternalProvisionClientAsync:{ts}");

setup ??= cScopeInfo.Setup;

if (cancellationToken.IsCancellationRequested)
Expand All @@ -393,6 +409,10 @@ public async Task<SyncResult> SynchronizeAsync(string scopeName, SyncSetup setup
(context, clientSyncChanges) = await this.LocalOrchestrator.InternalGetChangesAsync(cScopeInfo, context, cScopeInfoClient,
default, default, cancellationToken, progress).ConfigureAwait(false);

ts = await this.LocalOrchestrator.GetLocalTimestampAsync();
Console.WriteLine($"SYNC TS InternalGetChangesAsync:{ts}");
Debug.WriteLine($"SYNC TS InternalGetChangesAsync:{ts}");

if (cancellationToken.IsCancellationRequested)
cancellationToken.ThrowIfCancellationRequested();

Expand Down Expand Up @@ -445,6 +465,10 @@ await this.RemoteOrchestrator.InternalApplyThenGetChangesAsync(
cScopeInfo, cScopeInfoClient, context, serverSyncChanges, clientSyncChanges, reverseConflictResolutionPolicy, snapshotApplied, default, default,
cancellationToken, progress).ConfigureAwait(false);

ts = await this.LocalOrchestrator.GetLocalTimestampAsync();
Console.WriteLine($"SYNC TS InternalApplyChangesAsync:{ts}");
Debug.WriteLine($"SYNC TS InternalApplyChangesAsync:{ts}");

completeTime = DateTime.UtcNow;
this.LocalOrchestrator.CompleteTime = completeTime;
this.RemoteOrchestrator.CompleteTime = completeTime;
Expand Down Expand Up @@ -501,6 +525,10 @@ await this.RemoteOrchestrator.InternalApplyThenGetChangesAsync(
context = await this.LocalOrchestrator.InternalEndSessionAsync(context, result, clientSyncChanges, syncException, cancellationToken, progress).ConfigureAwait(false);
context = await this.RemoteOrchestrator.InternalEndSessionAsync(context, result, serverSyncChanges, syncException, cancellationToken, progress).ConfigureAwait(false);

var ts = await this.LocalOrchestrator.GetLocalTimestampAsync();
Console.WriteLine($"SYNC TS InternalEndSessionAsync:{ts}");
Debug.WriteLine($"SYNC TS InternalEndSessionAsync:{ts}");

}
catch { }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,57 +23,6 @@ namespace Dotmim.Sync.Tests.UnitTests
{
public partial class InterceptorsTests
{

private void TestReader(DbConnection connection, DbTransaction transaction, string add)
{
var sqlCommand = new SqlCommand("Select * from SalesLT.ProductCategory_tracking")
{
Connection = connection as SqlConnection,
Transaction = transaction as SqlTransaction,
CommandType = CommandType.Text
};

var syncTable = new SyncTable();

using var reader = sqlCommand.ExecuteReader();

syncTable.Load(reader);

Console.WriteLine("ProductCategory tracking rows");
Debug.WriteLine("ProductCategory tracking rows");

foreach (var row in syncTable.Rows)
{
Debug.WriteLine($"{add}{row}");
Console.WriteLine($"{add}{row}");
}

sqlCommand = new SqlCommand("Select * from SalesLT.Product_tracking")
{
Connection = connection as SqlConnection,
Transaction = transaction as SqlTransaction,
CommandType = CommandType.Text
};

syncTable = new SyncTable();

reader.Close();

using var reader2 = sqlCommand.ExecuteReader();

syncTable.Load(reader2);

Console.WriteLine("Product tracking rows");
Debug.WriteLine("Product tracking rows");

foreach (var row in syncTable.Rows)
{
Debug.WriteLine($"{add}{row}");
Console.WriteLine($"{add}{row}");
}
reader2.Close();
}

[Fact]
public async Task LocalOrchestrator_MetadataCleaning()
{
Expand Down Expand Up @@ -125,31 +74,19 @@ public async Task LocalOrchestrator_MetadataCleaning()
await ctx.SaveChangesAsync();
}

var ts = await localOrchestrator.GetLocalTimestampAsync();
Console.WriteLine($"Pass 1. TS:{ts}");
Debug.WriteLine($"Pass 1. TS:{ts}");


var cleaning = 0;
var cleaned = 0;

localOrchestrator.OnMetadataCleaning(args =>
{
cleaning++;
Console.WriteLine($"Pass 1. {args.Message}");
Debug.WriteLine($"Pass 1. {args.Message}");
TestReader(args.Connection, args.Transaction, "OnMetadataCleaning Pass 1:");
});

localOrchestrator.OnMetadataCleaned(args =>
{
cleaned++;
Assert.Equal(0, args.DatabaseMetadatasCleaned.RowsCleanedCount);
Assert.Empty(args.DatabaseMetadatasCleaned.Tables);
Console.WriteLine($"Pass 1. {args.Message}");
Debug.WriteLine($"Pass 1. {args.Message}");
TestReader(args.Connection, args.Transaction, "OnMetadataCleaned Pass 1:");

});


Expand All @@ -166,25 +103,14 @@ public async Task LocalOrchestrator_MetadataCleaning()
cleaning = 0;
cleaned = 0;

ts = await localOrchestrator.GetLocalTimestampAsync();
Console.WriteLine($"Pass 2. TS:{ts}");
Debug.WriteLine($"Pass 2. TS:{ts}");


localOrchestrator.OnMetadataCleaning(args =>
{
cleaning++;
Console.WriteLine($"Pass 2. {args.Message}");
Debug.WriteLine($"Pass 2. {args.Message}");
TestReader(args.Connection, args.Transaction, "OnMetadataCleaning Pass 2:");
});

localOrchestrator.OnMetadataCleaned(args =>
{
cleaned++;
Console.WriteLine($"Pass 2. {args.Message}");
Debug.WriteLine($"Pass 2. {args.Message}");
TestReader(args.Connection, args.Transaction, "OnMetadataCleaned Pass 2:");
});

// Making a second empty sync.
Expand All @@ -194,12 +120,6 @@ public async Task LocalOrchestrator_MetadataCleaning()
Assert.Equal(0, cleaning);
Assert.Equal(0, cleaned);

ts = await localOrchestrator.GetLocalTimestampAsync();
Console.WriteLine($"Pass 3. TS:{ts}");
Debug.WriteLine($"Pass 3. TS:{ts}");



// Server side : Create a product category
productCategoryName = HelperDatabase.GetRandomName();
productCategoryId = productCategoryName.ToUpperInvariant().Substring(0, 6);
Expand All @@ -212,49 +132,26 @@ public async Task LocalOrchestrator_MetadataCleaning()
await ctx.SaveChangesAsync();
}

ts = await localOrchestrator.GetLocalTimestampAsync();
Console.WriteLine($"Pass 3 bis. TS:{ts}");
Debug.WriteLine($"Pass 3 bis. TS:{ts}");



// Reset interceptors
localOrchestrator.ClearInterceptors();

cleaning = 0;
cleaned = 0;


localOrchestrator.OnMetadataCleaning(args =>
{
cleaning++;
Console.WriteLine($"Pass 3. {args.Message}");
Debug.WriteLine($"Pass 3. {args.Message}");

TestReader(args.Connection, args.Transaction, "OnMetadataCleaning Pass 3:");


});

localOrchestrator.OnMetadataCleaned(args =>
{
cleaned++;
Console.WriteLine($"Pass 3. {args.Message}");
Debug.WriteLine($"Pass 3. {args.Message}");
TestReader(args.Connection, args.Transaction, "OnMetadataCleaned Pass 3:");
Assert.Equal(1, args.DatabaseMetadatasCleaned.RowsCleanedCount);
Assert.Single(args.DatabaseMetadatasCleaned.Tables);
Assert.Equal("SalesLT", args.DatabaseMetadatasCleaned.Tables[0].SchemaName);
Assert.Equal("ProductCategory", args.DatabaseMetadatasCleaned.Tables[0].TableName);
Assert.Equal(1, args.DatabaseMetadatasCleaned.Tables[0].RowsCleanedCount);

});
var s4 = await agent.SynchronizeAsync(scopeName);

Assert.Equal(1, cleaning);
Assert.Equal(1, cleaned);


// Server side : Create a product category and a product
// Create a productcategory item
// Create a new product on server
Expand All @@ -281,20 +178,14 @@ public async Task LocalOrchestrator_MetadataCleaning()
cleaning = 0;
cleaned = 0;


localOrchestrator.OnMetadataCleaning(args =>
{
cleaning++;
Console.WriteLine($"Pass 4. {args.Message}");
Console.WriteLine($"Pass 4. OnMetadataCleaning cleaning count:{cleaning}");
});

localOrchestrator.OnMetadataCleaned(args =>
{
cleaned++;
Assert.Equal(0, args.DatabaseMetadatasCleaned.RowsCleanedCount);
Console.WriteLine($"Pass 4. {args.Message}");
Console.WriteLine($"Pass 4. OnMetadataCleaning cleaned count:{cleaned}");
});

var s5 = await agent.SynchronizeAsync(scopeName);
Expand All @@ -303,7 +194,6 @@ public async Task LocalOrchestrator_MetadataCleaning()
Assert.Equal(1, cleaning);
Assert.Equal(1, cleaned);


HelperDatabase.DropDatabase(ProviderType.Sql, dbNameSrv);
HelperDatabase.DropDatabase(ProviderType.Sql, dbNameCli);
}
Expand Down

0 comments on commit 36f481f

Please sign in to comment.