Skip to content

Commit

Permalink
Ticket #10 : Create keyspace
Browse files Browse the repository at this point in the history
  • Loading branch information
thabart committed Oct 31, 2020
1 parent da4cfd5 commit 402ac0d
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<VersionPrefix>2.0.2</VersionPrefix>
<VersionPrefix>2.0.3</VersionPrefix>
<Authors>SimpleIdServer</Authors>
<Owners>SimpleIdServer</Owners>
</PropertyGroup>
Expand Down
13 changes: 11 additions & 2 deletions EFCore.Cassandra.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.0
# Visual Studio Version 16
VisualStudioVersion = 16.0.30406.217
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "01. Core Layer", "01. Core Layer", "{4920F8DE-E217-452A-865A-E47DAC924B5F}"
EndProject
Expand All @@ -20,6 +20,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.Cassandra.Tests", "t
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.Cassandra.Samples", "samples\EFCore.Cassandra.Samples\EFCore.Cassandra.Samples.csproj", "{84CB9B7A-BDCF-4AF6-8C02-80405EB54C93}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "04. Benchmarks", "04. Benchmarks", "{46930201-AD6E-448E-B8D7-95B26ABD9BB6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EFCore.Cassandra.Benchmarks", "src\EFCore.Cassandra.Benchmarks\EFCore.Cassandra.Benchmarks.csproj", "{BBB1B39C-42FF-43AD-AF77-33B0018FD0E6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -38,6 +42,10 @@ Global
{84CB9B7A-BDCF-4AF6-8C02-80405EB54C93}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84CB9B7A-BDCF-4AF6-8C02-80405EB54C93}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84CB9B7A-BDCF-4AF6-8C02-80405EB54C93}.Release|Any CPU.Build.0 = Release|Any CPU
{BBB1B39C-42FF-43AD-AF77-33B0018FD0E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BBB1B39C-42FF-43AD-AF77-33B0018FD0E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BBB1B39C-42FF-43AD-AF77-33B0018FD0E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BBB1B39C-42FF-43AD-AF77-33B0018FD0E6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -46,6 +54,7 @@ Global
{2D74D363-66B9-424B-BB34-468BEF0A2F07} = {4920F8DE-E217-452A-865A-E47DAC924B5F}
{BE0A2541-1253-4917-A070-4BB8F71F4704} = {BCAC9560-F9EC-4C11-A0E2-D3CAC0759519}
{84CB9B7A-BDCF-4AF6-8C02-80405EB54C93} = {D43C01D1-8661-4A06-B3D8-5CD1A9AC1DB3}
{BBB1B39C-42FF-43AD-AF77-33B0018FD0E6} = {46930201-AD6E-448E-B8D7-95B26ABD9BB6}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {13BDB38B-AFCC-4B2C-B0F9-404FB6249216}
Expand Down
14 changes: 14 additions & 0 deletions src/EFCore.Cassandra.Benchmarks/EFCore.Cassandra.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EFCore.Cassandra\EFCore.Cassandra.csproj" />
</ItemGroup>
</Project>
43 changes: 43 additions & 0 deletions src/EFCore.Cassandra.Benchmarks/FakeDbContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) SimpleIdServer. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
using EFCore.Cassandra.Benchmarks.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Cassandra.Storage;
using Microsoft.EntityFrameworkCore.Migrations;

namespace EFCore.Cassandra.Benchmarks
{
public class FakeDbContext : DbContext
{
public DbSet<Applicant> Applicants { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseCassandra("Contact Points=127.0.0.1;", opt =>
{
opt.MigrationsHistoryTable(HistoryRepository.DefaultTableName, "cv");
});
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
var timeUuidConverter = new TimeUuidToGuidConverter();
modelBuilder.ForCassandraAddKeyspace("cv", new KeyspaceReplicationSimpleStrategyClass(2));
modelBuilder.Entity<Applicant>()
.ToTable("applicants", "cv")
.HasKey(p => new { p.Id, p.Order });
modelBuilder.Entity<Applicant>()
.ForCassandraSetClusterColumns(_ => _.Order)
.ForCassandraSetClusteringOrderBy(new[] { new CassandraClusteringOrderByOption("Order", CassandraClusteringOrderByOptions.ASC) });
modelBuilder.Entity<Applicant>()
.Property(p => p.TimeUuid)
.HasConversion(new TimeUuidToGuidConverter());
modelBuilder.Entity<Applicant>()
.Property(p => p.Id)
.HasColumnName("id");
modelBuilder.Entity<ApplicantAddress>()
.ToUserDefinedType("applicant_addr", "cv")
.HasNoKey();
}
}
}
57 changes: 57 additions & 0 deletions src/EFCore.Cassandra.Benchmarks/InsertData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) SimpleIdServer. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
using BenchmarkDotNet.Attributes;
using EFCore.Cassandra.Benchmarks.Models;
using System;
using System.Collections.Generic;
using System.Linq;

namespace EFCore.Cassandra.Benchmarks
{
public class InsertData : IDisposable
{
private readonly FakeDbContext _dbContext;
private readonly Applicant[] _applicants;

public InsertData()
{
_dbContext = new FakeDbContext();
_applicants = Enumerable.Range(1, 5).Select(_ => BuildApplicant()).ToArray();
}

public void Dispose()
{
_dbContext.Dispose();
}

[Benchmark]
public void Add100Applicants()
{
foreach (var applicant in _applicants)
{
_dbContext.Applicants.Add(applicant);
}

_dbContext.SaveChanges();
}

[Benchmark]
public void AddRange100Applicants()
{
_dbContext.Applicants.AddRange(_applicants);
_dbContext.SaveChanges();
}

private static Applicant BuildApplicant()
{
return new Applicant
{
Id = Guid.NewGuid(),
Order = 0,
Dic = new Dictionary<string, string>(),
Lst = new List<string>(),
LstInt = new List<int>()
};
}
}
}
37 changes: 37 additions & 0 deletions src/EFCore.Cassandra.Benchmarks/Models/Applicant.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) SimpleIdServer. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
using Cassandra;
using System;
using System.Collections.Generic;
using System.Net;
using System.Numerics;

namespace EFCore.Cassandra.Benchmarks.Models
{
public class Applicant
{
public Guid Id { get; set; }
public int Order { get; set; }
public Guid ApplicantId { get; set; }
public string LastName { get; set; }
public long Long { get; set; }
public bool Bool { get; set; }
public decimal Decimal { get; set; }
public double Double { get; set; }
public float Float { get; set; }
public int Integer { get; set; }
public short SmallInt { get; set; }
public DateTimeOffset DateTimeOffset { get; set; }
public TimeUuid TimeUuid { get; set; }
public sbyte Sbyte { get; set; }
public BigInteger BigInteger { get; set; }
public byte[] Blob { get; set; }
public LocalDate LocalDate { get; set; }
public IPAddress Ip { get; set; }
public LocalTime LocalTime { get; set; }
public IList<string> Lst { get; set; }
public IList<int> LstInt { get; set; }
public IDictionary<string, string> Dic { get; set; }
public ApplicantAddress Address { get; set; }
}
}
9 changes: 9 additions & 0 deletions src/EFCore.Cassandra.Benchmarks/Models/ApplicantAddress.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

namespace EFCore.Cassandra.Benchmarks.Models
{
public class ApplicantAddress
{
public int StreetNumber { get; set; }
public string City { get; set; }
}
}
15 changes: 15 additions & 0 deletions src/EFCore.Cassandra.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) SimpleIdServer. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
using BenchmarkDotNet.Running;
using System.Threading.Tasks;

namespace EFCore.Cassandra.Benchmarks
{
internal class Program
{
private static async Task Main(string[] args)
{
BenchmarkRunner.Run<InsertData>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,17 +285,12 @@ private class MigrationOpComparer : IComparer<MigrationOperation>
{
public int Compare(MigrationOperation x, MigrationOperation y)
{
if (x is CreateUserDefinedTypeOperation)
if (y is CreateUserDefinedTypeOperation || y is EnsureSchemaOperation)
{
return -1;
return 1;
}

if (y is CreateUserDefinedTypeOperation)
{
return -1;
}

return 1;
return -1;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.EntityFrameworkCore.Storage;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading;
Expand Down

0 comments on commit 402ac0d

Please sign in to comment.